Skip to content

Instantly share code, notes, and snippets.

@dcaliri
Created June 9, 2010 18:47
Show Gist options
  • Save dcaliri/431969 to your computer and use it in GitHub Desktop.
Save dcaliri/431969 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' => '--..' }
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