From: Julian Leviston Date: 2013-03-30T16:06:38+09:00 Subject: Re: Translation Project On 30/03/2013, at 3:42 AM, Jeremy Henderson wrote: > Yes, I love how compressed it is. Like Regis' though, it can't handle > apostrophes. I assume I'll need to add some kind of exception for them > into it. > > -- > Posted via http://www.ruby-forum.com/. > Yeah, you didn't specify what you wanted it to do. This one allows you to specify with the default_char variable what unspecified chars will be mapped to (presently it's at a space, but you could replace with an empty string or some other default char/string easily). class String def dna_conv default_char = " " dict = {"A" => "ABCDEF", "B" => "GHIJKL", "C" => "MNOPQR", "D" => "STUVWXYZ"} self.upcase.each_char.map{|input_char| found_pair = dict.detect{|key, value| value.include?(input_char)}; (found_pair && found_pair.first) || default_char}.join end end puts "DNAS: Sequencing Open... Input? " while (word=$stdin.gets.chomp).size>1 puts word.dna_conv puts puts "DNAS: Additional Input? " end