r/dailyprogrammer • • Feb 15 '12
[2/15/2012] Challenge #7 [easy]
Write a program that can translate Morse code in the format of ...---...
A space and a slash will be placed between words. ..- / --.-
For bonus, add the capability of going from a string to Morse code.
Super-bonus if your program can flash or beep the Morse.
This is your Morse to translate:
.... . .-.. .-.. --- / -.. .- .. .-.. -.-- / .--. .-. --- --. .-. .- -- -- . .-. / --. --- --- -.. / .-.. ..- -.-. -.- / --- -. / - .... . / -.-. .... .- .-.. .-.. . -. --. . ... / - --- -.. .- -.--
17
Upvotes
2
u/Koldof 0 0 Feb 15 '12 edited Feb 15 '12
This seems quite complicated to do in C++.. Still working on my shoddy attempt.
EDIT: Here is mine. I eventually figured out a method (most stolen from Duncan) and used that. Now, I tried to get the extra credit, but mine wouldn't work, for some weird reason.
4
u/somethinyellow Feb 15 '12
A quick ruby solution for decryption
4
u/[deleted] Feb 16 '12
I made this one in ActionScript 3 (without the Super-bonus), and I guess I'll only post the class that handles encoding/decoding morse code since the rest of the code in pretty much irrelevant.
4
u/Fustrate 0 0 May 03 '12 edited May 03 '12
Python encode and decode in four lines :D
1
u/refact0r Feb 16 '12
I used python, included a method for encoding aswell as decoding a morse message. One "Feature" is that the string with morse data must end in a space :S
3
u/[deleted] Feb 15 '12
Javascript. Beeping would require an object in the DOM but this is an HTML-free version. I found an old website that has a Morse converter in Javascript, but I only copied the alphabet string from it because I am lazy. :)
http://pastebin.com/EFLPvSGB
3
u/Woooza Feb 16 '12 edited Feb 16 '12
2
u/robin-gvx 0 2 Feb 15 '12 edited Feb 15 '12
-. .. -.-. . / -.-. .... .- .-.. .-.. . -. --. .
2
u/mattryan Feb 15 '12
Java using BiMaps from Google's Guava library
2
u/cooper6581 Feb 15 '12
Program in C with the bonus (no super bonus unfortunately) http://codepad.org/Hskwpohy
2
u/hippibruder Feb 15 '12
still learning python. the play method only works with windows
1
u/drb226 0 0 Feb 15 '12
85 lines of Haskell: http://hpaste.org/63765
Lots of boilerplatey lines, doesn't handle errors very gracefully. But it does encode and decode rather nicely. Assumes whitespace between each character, and space slash space between each word. Requires
cabal install split.1
u/Kealper Feb 16 '12 edited Feb 16 '12
AutoIt (Pastebin link)
Since this one was a bit longer than I'd like for posting on here (and does a bit of weird things in the language) I figured I would post this one to pastebin instead, for the syntax highlighting and such.
It does both converting to and from Morse by calling the same Convert function (automatically detects if it's English or Morse and outputs accordingly), so it does the bonus, and it supports converting both letters and numbers.
And lastly, for the super-bonus, call it like this to make it beep out the Morse (as it would actually sound over real CW operations):
It's nice to see my ham radio know-how is of some use here :P
EDIT: forgot to put my program's output for the Morse message in the OP:
1
u/[deleted] Feb 16 '12
no extra credit, and is broken up into three files, but:
main.cpp:
morse_tree.h
morse_code.txt
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 --.. 1 .---- 2 ..--- 3 ...-- 4 ....- 5 ..... 6 -.... 7 --... 8 ---.. 9 ----. 0 -----
output:
1
u/stiggz Feb 17 '12
Seven lines of perl code
1
u/_lambda_ Feb 17 '12 edited Feb 17 '12
A solution in racket (look, no hash or lookup table):
; bonus: encoding
1
u/jnaranjo Feb 19 '12
Python solution
http://pastebin.com/TYTgsEWt
Quick and simple Uses a pickled dictionary of a morse code alphabet, which is also pasted!
1
u/Should_I_say_this Jun 20 '12
Wow this took me a long time but I got it! Python 3.0!
1
u/Jatak 0 0 Jun 22 '12 edited Jun 22 '12
In Python 3.2.3
I'd make it check that the characters entered are in the correct format and range, but I'm just too damn lazy.
1
u/wocamai Aug 06 '12
In Python 2.7. used a list to map morse to normal alphabet and back, so it doesn't have unexpected functionality but i also didn't bother to catch the errors it throws.
1
u/ragtag_creature Aug 27 '22
R
0
u/irlKryst Feb 15 '12
oh this sounds fun :) ill do this later if i have time.