Created
January 11, 2011 05:38
-
-
Save awilkening/774072 to your computer and use it in GitHub Desktop.
converts english into morse code
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
str = '' | |
counter = 1 | |
ARGV.each do |a| | |
counter = counter + 1 | |
a.each_char do |char| | |
char = char.to_s.downcase | |
case char | |
when 'a' | |
str += '.-' | |
when 'b' | |
str += '-...' | |
when 'c' | |
str += '-.-.' | |
when 'd' | |
str += '-..' | |
when 'e' | |
str += '.' | |
when 'f' | |
str += '..-.' | |
when 'g' | |
str += '--.' | |
when 'h' | |
str += '....' | |
when 'i' | |
str += '..' | |
when 'j' | |
str += '.---' | |
when 'k' | |
str += '-.-' | |
when 'l' | |
str += '.-..' | |
when 'm' | |
str += '--' | |
when 'n' | |
str += '-.' | |
when 'o' | |
str += '---' | |
when 'p' | |
str += '.--.' | |
when 'q' | |
str += '--.-' | |
when 'r' | |
str += '.-.' | |
when 's' | |
str += '...' | |
when 't' | |
str += '-' | |
when 'u' | |
str += '..-' | |
when 'v' | |
str += '...-' | |
when 'w' | |
str += '.--' | |
when 'x' | |
str += '-..-' | |
when 'y' | |
str += '-.--' | |
when 'z' | |
str += '--..' | |
when '1' | |
str += '.----' | |
when '2' | |
str += '..---' | |
when '3' | |
str += '...--' | |
when '4' | |
str += '....-' | |
when '5' | |
str += '.....' | |
when '6' | |
str += '-....' | |
when '7' | |
str += '--...' | |
when '8' | |
str += '---..' | |
when '9' | |
str += '----.' | |
when '0' | |
str += '-----' | |
when ' ' | |
str += ' ' | |
end | |
end | |
str += ' ' unless ARGV.size - counter < 1 | |
end | |
puts str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment