Created
June 20, 2010 05:21
-
-
Save manveru/445586 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Morse = Object clone | |
Morse translation-table = [ | |
"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", "--.." | |
"Ä", ".-.-" | |
"Á", ".--.-" | |
"Å", ".--.-" | |
"Ch", "----" | |
"É", "..-.." | |
"Ñ", "--.--" | |
"Ö", "---." | |
"Ü", "..--" | |
"0", "-----" | |
"1", ".----" | |
"2", "..---" | |
"3", "...--" | |
"4", "....-" | |
"5", "....." | |
"6", "-...." | |
"7", "--..." | |
"8", "---.." | |
"9", "----." | |
".", ".-.-.-" | |
",", "--..--" | |
":", "---..." | |
"?", "..--.." | |
"'", ".----." | |
"-", "-....-" | |
"/", "-..-." | |
"(", "-.--.-" | |
'"', ".-..-." | |
"@", ".--.-." | |
"=", "-...-" | |
] to-hash | |
Morse to-morse: = (string| | |
string map: [c| | |
(self translation-table at: (c uppercase)) + " " | |
] chop | |
) | |
Morse to-text: = (string| | |
((morse split) map: [m| | |
(self translation-table at-value: m) | |
]) join | |
) | |
test = "SOS" | |
morse = Morse to-morse: test | |
puts: morse | |
text = Morse to-text: morse | |
puts: text | |
# puts: (Morse to-morse: "ABCDEFGHIJKLMNOPQRSTUVWXYZÄÁÅCÉÑÖÜ0123456789. ,:? '-/(@=") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment