Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Count Morse by Pavellver
D = {
"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": "--..",
}
def count_morse(message: str, letters: str) -> int:
counter = 0
for i in letters:
if message == D[i]:
return 1
if message.startswith(D[i]):
counter += count_morse(message[len(D[i]):], ''.join(set(letters).difference(set(i))))
return counter
May 8, 2023
Comments: