Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@npras
Created July 3, 2012 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npras/3038253 to your computer and use it in GitHub Desktop.
Save npras/3038253 to your computer and use it in GitHub Desktop.
Ruby Challenge 6: Morsels and Dimes
# 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