Skip to content

Instantly share code, notes, and snippets.

@basgys
Created March 25, 2012 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save basgys/2193099 to your computer and use it in GitHub Desktop.
Save basgys/2193099 to your computer and use it in GitHub Desktop.
Morse to english
map = {
'.-' => 'A',
'-...' => 'B',
'-.-.' => 'C',
'-..' => 'D',
'.' => 'E',
'..-.' => 'F',
'--.' => 'G',
'....' => 'H',
'..' => 'I',
'.---' => 'J',
'-.-' => 'K',
'.-..' => 'L',
'--' => 'M',
'-.' => 'N',
'---' => 'O',
'.--.' => 'P',
'--.-' => 'Q',
'.-.' => 'R',
'...' => 'S',
'-' => 'T',
'..-' => 'U',
'...-' => 'V',
'.--' => 'W',
'-..-' => 'X'
}
input = ".... . .-.. .--. -- . --- ..- - --- ..-. - .... .. ... .-- . .-.. .-.."
words = input.split ' '
twords = words.map do |w|
w.split(' ').map {|morse_letter| map[morse_letter] }.join
end
puts twords.join ' '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment