Created
July 3, 2012 07:23
-
-
Save npras/3038253 to your computer and use it in GitHub Desktop.
Ruby Challenge 6: Morsels and Dimes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.therubygame.com/challenges/6/submissions | |
module RubyChallenge | |
extend self | |
MORSE = { | |
A: '.-', B: '-...', C: '-.-.', D: '-..', E: '.', F: '..-.', G: '--.', | |
H: '....', I: '..', J: '.---', K: '-.-', L: '.-..', M: '--', N: '-.', | |
O: '---', P: '.--.', Q: '--.-', R: '.-.', S: '...', T: '-', U: '..-', | |
V: '...-', W: '.--', X: '-..-', Y: '-.--', Z: '--..' | |
} | |
def morse_to_eng(morse) | |
eng = "" | |
morse.split(" ").each do |word| | |
eng << word.split(" ").map do |letter_code| | |
MORSE.invert[letter_code] | |
end.join << " " | |
end | |
eng.chop.upcase | |
end | |
end | |
p RubyChallenge.morse_to_eng ".... . .-.. .--. -- . --- ..- - --- ..-. - .... .. ... .-- . .-.. .-.." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment