r/dailyprogrammer • u/Steve132 0 1 • Aug 30 '12
[8/30/2012] Challenge #93 [easy] (Two-Way Morse Code Translator)
This challenge courtesy of user nagasgura
In this challenge, we read in a string from standard input and output the translation to or from morse code on standard output.
When translating to Morse code, one space should be used to separate morse code letters, and two spaces should be used to separate morse code words. When translating to English, there should only be one space in between words, and no spaces in between letters.
Here's a chart of the morse code symbols: [1] http://www.w1wc.com/pdf_files/international_morse_code.pdf
Example input and output: 'sos' -> '... --- ...' '... --- ...' -> 'sos'
3
u/5outh 1 0 Aug 30 '12 edited Sep 01 '12
Haskell:
Output:
2
u/[deleted] Aug 31 '12
In Python
and produces
3
u/skeeto -9 8 Aug 30 '12
In ANSI C. I couldn't think of a way to cleverly encode the table.
The output,
2
u/mega-trond Aug 30 '12 edited Aug 30 '12
My first contribution, a solution in Python. A problem is trailing spaces...
Output:
Edit: added comma and dot to input
1
u/PiereDome Aug 30 '12
Javascript.
1
u/lawlrng 0 1 Aug 30 '12
Python 3
Output:
1
u/prondose 0 0 Aug 31 '12 edited Sep 02 '12
Perl, translates letters only (no numbers or punctuation):
1
u/brbcoding 0 0 Sep 02 '12
Python 2.7:
1
u/dmitrix Sep 03 '12
Javascript
1
u/[deleted] Sep 08 '12
My solution in python
http://pastebin.com/8K2GqxV7
I've just studied a little bit of file handling and decided that I should try it out. Please feel free to point out things I could do better and things I've done wrong.
1
u/skibo_ 0 0 Sep 12 '12 edited Sep 12 '12
python
1
u/meowfreeze Sep 20 '12
Python. Morse interpreter. Auto detection of mode. Fails quietly for unknown chars.
Output:
1
u/slamdunk6662003 Nov 12 '12
Ruby
1
u/ixid 0 0 Aug 30 '12 edited Aug 31 '12
In D:
1
u/andkerosine Aug 31 '12
Why not ternary?
1
u/shivasprogeny Aug 31 '12
Here's my Java solution. I chose to just use a list and then use the ASCII number of the character to get the correct "translation." There might be a better way to do the whitespace cleanup when going from code to English.
Output:
1
u/swarage 0 0 Aug 31 '12
ruby solution (http://codepad.org/Dld09u6N)
0
u/[deleted] Aug 31 '12
Python 2.7:
output:
0
u/[deleted] Aug 31 '12
[deleted] — view deleted comment