Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
recursive function solution in Clear category for Count Morse by Tinus_Trotyl
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, count=0) -> int: # set count initial to 0
if not letters:
return count + 1
for i, letter in enumerate(letters):
if message.startswith(D[letter]):
count = count_morse(message[len(D[letter]):], letters[:i] + letters[i + 1:], count)
return count
April 13, 2023
Comments: