Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Morse Clock by Orthomonalus
def checkio(time_string):
h, m, s = time_string.split(':')
h1, h2 = h.zfill(2)
m1, m2 = m.zfill(2)
s1, s2 = s.zfill(2)
def to_morse(digit, bits):
binary = format(int(digit), f'0{bits}b')
return ''.join('.' if bit == '0' else '-' for bit in binary)
h1_morse = to_morse(h1, 2)
h2_morse = to_morse(h2, 4)
m1_morse = to_morse(m1, 3)
m2_morse = to_morse(m2, 4)
s1_morse = to_morse(s1, 3)
s2_morse = to_morse(s2, 4)
return f'{h1_morse} {h2_morse} : {m1_morse} {m2_morse} : {s1_morse} {s2_morse}'
print("Example:")
print(checkio("10:37:49"))
# These "asserts" are used for self-checking
assert checkio("10:37:49") == ".- .... : .-- .--- : -.. -..-"
assert checkio("21:34:56") == "-. ...- : .-- .-.. : -.- .--."
assert checkio("00:1:02") == ".. .... : ... ...- : ... ..-."
assert checkio("23:59:59") == "-. ..-- : -.- -..- : -.- -..-"
assert checkio("0:10:2") == ".. .... : ..- .... : ... ..-."
print("The mission is done! Click 'Check Solution' to earn rewards!")
April 17, 2025
Comments: