Skip to content

Instantly share code, notes, and snippets.

View dcaliri's full-sized avatar

Diego Caliri dcaliri

  • Eventioz
  • Mendoza, Argentina
View GitHub Profile
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
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