Skip to content

Latest commit

 

History

History
 
 

morsecode 2.0

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Morse Code 2.0

DO NOT ATTEMPT!

This challenge sounded great on paper, but in practice it would require incredibly tedious or convoluted solutions. Some of you have, in fact, completed this challenge, and that's awesome, but let's be clear: creating & using a lookup array is possibly the only sensible solution to translating morse code to regular english. That said, you can find a rather elegant, if overly elaborate, solution to the problem here. It's worth pointing out though that even I didn't follow my own rules; I pulled in the original lookup array but used it to construct a parse tree (technically, a binary heap). If you'd like an explanation for how this script works, come see @bbatsche and I'd be happy to explain it.

Original Instructions

By now you all have become experts at translating English to morse code, it's time to do the reverse. But there's a catch! Unlike the previous challenge, we aren't giving you a PHP array for doing your lookup; in fact you are not allowed to use any kind of lookup array. Instead, you must parse the string using nested if and/or switch statements. Just like before spaces will be replaced with / characters, but to make things simpler we will also separate each letter with a space. So for example, the following:

.... . .-.. .-.. --- / .-- --- .-. .-.. -..

would translate to:

hello world

We've created three separate input files for you to work from, divided into three different tiers. The first file contains sentences using only alphabetic characters. The second file uses both alpha and numeric characters. Finally, the third file contains sentences with alpha numeric characters as well as special characters.

Below are the tables you'll need to construct the logic; we've sorted them in a manner that should make them easier to work with. They are also in the file morse.tables.txt.

Alpha Characters

Morse | Alpha

--------- | ------ - | T -- | M --- | O --. | G --.- | Q --.. | Z -. | N -.- | K -.-- | Y -.-. | C -.. | D -..- | X -... | B . | E .- | A .-- | W .--- | J .--. | P .-. | R .-.. | L .. | I ..- | U ..-. | F ... | S ...- | V .... | H

Numeric Characters

Morse | Alpha

--------- | ------ ----- | 0 ----. | 9 ---.. | 8 --... | 7 -.... | 6 .---- | 1 ..--- | 2 ...-- | 3 ....- | 4 ..... | 5

Other Characters

Morse | Alpha

--------- | ------ ---... | : --..-- | , -.--.- | ) -.--.- | ( -.-.-- | ! -.-.-. | ; -..-. | / -...- | = -....- | - .-.-. | + .-.-.- | . .-..-. | " .-... | & ..--.- | _ ..--.. | ? ...-..- | $