006 Morse Code
Your boss is elated; the business has decided that your next flagship product is going to disrupt the Morse code space by digitising Morse transmissions into an efficient binary format, with each bit representing a different signal duration.
“What about the pauses?”, you ask. “What pauses?” “Well, without pauses a Morse code message is ambiguous. For example, “E” (.) is a prefix of “I” (..), so without any pauses, “..” could either mean “EE or “I. Your boss’ elation soon turns to horror—“the marketing materials have already been printed, it’s too late to change anything now”.
After a quick brainstorming session with your boss, you come up with a solution to the ambiguity problem: A two byte checksum will be transmitted along with the message, which can be used to eliminate ambiguous messages. The checksum is computed like this:
Start with 0 as the checksum. For each transmitted character, recompute the checksum by first multiplying it by ten, then add the (0-indexed) position of the current character in the morse code alphabet; finally apply modulo 2048 to the result.
(Assume the Morse code alphabet is ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 and the encoding is the ITU standard as described here: https://rsgb.org/main/files/2012/10/Morse_Code_Sheet_01.pdf)
For example, the checksum of the message HELLO would be:
H: (0 × 10 + 7) mod 2048 = 7
E: (7 × 10 + 4) mod 2048 = 74
L: (74 × 10 + 11) mod 2048 = 751
L: (751 × 10 + 11) mod 2048 = 1377
O: (1377 × 10 + 14) mod 2048 = 1496
Write a function "decode" that, given a string in this "compact" Morse encoding and a checksum, returns all valid interpretations of that message. The input message will be represented as dots and dashes, for clarity.
For example, given the input ......-...-..--- and a checksum of 1496, the
program should return the list ["HELLO"].