Skip to content

Instantly share code, notes, and snippets.

@dcaliri
Created June 9, 2010 21:09
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 dcaliri/432174 to your computer and use it in GitHub Desktop.
Save dcaliri/432174 to your computer and use it in GitHub Desktop.
def morse(s)
dictionary = { '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' => '--..', '0' => '-----', '1' => '.----', '2' => '..---', '3' => '...--', '4' => '....-', '5' => '.....', '6' => '-....', '7' => '--...', '8' => '---..', '9' => '----.' }
word = ''
s.downcase!
for i in 0..(s.length - 1) do
if dictionary[s[i,1]]
word << dictionary[s[i,1]]
elsif s[i,1] == ' '
word << ' '
end
end
word
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment