dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
2.8 KiB
2.8 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 6a22d77ddf034bc4e35b1d5c | Challenge 355: Morse Code | 29 | challenge-355 |
--description--
Given a Morse code string, return the decoded message using the following table:
| Code | Letter | Code | Letter |
|---|---|---|---|
.- |
A |
-. |
N |
-... |
B |
--- |
O |
-.-. |
C |
.--. |
P |
-.. |
D |
--.- |
Q |
. |
E |
.-. |
R |
..-. |
F |
... |
S |
--. |
G |
- |
T |
.... |
H |
..- |
U |
.. |
I |
...- |
V |
.--- |
J |
.-- |
W |
-.- |
K |
-..- |
X |
.-.. |
L |
-.-- |
Y |
-- |
M |
--.. |
Z |
- Letters are separated by a single space
- Words are separated by three spaces
--hints--
decode_morse("--..") should return "Z".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode_morse("--.."), "Z")`)
}})
decode_morse("... --- ...") should return "SOS".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode_morse("... --- ..."), "SOS")`)
}})
decode_morse("..-. .-. . . -.-. --- -.. . -.-. .- -- .--.") should return "FREECODECAMP".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode_morse("..-. .-. . . -.-. --- -.. . -.-. .- -- .--."), "FREECODECAMP")`)
}})
decode_morse(".... . .-.. .-.. --- .-- --- .-. .-.. -..") should return "HELLO WORLD".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode_morse(".... . .-.. .-.. --- .-- --- .-. .-.. -.."), "HELLO WORLD")`)
}})
decode_morse("- .... . --.- ..- .. -.-. -.- -... .-. --- .-- -. ..-. --- -..- .--- ..- -- .--. . -.. --- ...- . .-. - .... . .-.. .- --.. -.-- -.. --- --.") should return "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG".
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(decode_morse("- .... . --.- ..- .. -.-. -.- -... .-. --- .-- -. ..-. --- -..- .--- ..- -- .--. . -.. --- ...- . .-. - .... . .-.. .- --.. -.-- -.. --- --."), "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG")`)
}})
--seed--
--seed-contents--
def decode_morse(code):
return code
--solutions--
def decode_morse(code):
table = {
'.-': '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'
}
return ' '.join(
''.join(table[c] for c in word.split(' '))
for word in code.split(' ')
)