Created
March 25, 2012 11:48
-
-
Save basgys/2193099 to your computer and use it in GitHub Desktop.
Morse to english
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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