From: Harry Kakueki Date: 2012-12-07T22:40:45+09:00 Subject: Re: Trying to get "translator" to work On Fri, Dec 7, 2012 at 4:51 AM, JD KF wrote: > So, basically, I'm trying to get the below code to work properly for > "piglatin". I have gotten it to work with mulitple words, if the word > starts with a vowel, if the word starts with a consonant, and if the > word starts with two consonants. This was a hell of a lot of trial and > error getting to this point. This is not a complete solution, but maybe you can modify the 'if' statement to make the rules. I am a bit rusty with pig latin. def pig(w) arr = [] (1...w.size).each do |a| if w[0...a] !~ /[aeiou]/ or (w[0...(a-1)] !~ /[aeiou]/ and w[0...a] =~ /qu\z/) arr << w[a..-1]+w[0...a]+"ay" end end arr << w + "way" if w[0..0] =~ /[aeiou]/ arr[-1] end words = [ "square", "quiet", "bird", "apple","require","start","strength"] words.each{|f| p pig(f)} ## OUTPUT "aresquay" "ietquay" "irdbay" "appleway" "equireray" "artstay" "engthstray" Harry