Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
with generators expressions solution in Clear category for Morse Clock by Mikha_Kulakov
def morse_decode(number: str, length=2) -> str:
tmp = str(bin(int(number)))[2:]
tmp = '{}{}'.format((length - len(tmp)) * '0', tmp)
res = ''.join(map(lambda x: '.' if x=='0' else '-', tmp))
return res
def checkio(time_string: str) -> str:
h, m, s = (('0'+i)[-2:] for i in time_string.split(':'))
h = '{} {}'.format(morse_decode(h[0], 2), morse_decode(h[1], 4))
m = '{} {}'.format(morse_decode(m[0], 3), morse_decode(m[1], 4))
s = '{} {}'.format(morse_decode(s[0], 3), morse_decode(s[1], 4))
return "{} : {} : {}".format(h,m,s)
if __name__ == '__main__':
print("Example:")
print(checkio("10:37:49"))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio("10:37:49") == ".- .... : .-- .--- : -.. -..-", "First Test"
assert checkio("21:34:56") == "-. ...- : .-- .-.. : -.- .--.", "Second Test"
assert checkio("00:1:02") == ".. .... : ... ...- : ... ..-.", "Third Test"
assert checkio("23:59:59") == "-. ..-- : -.- -..- : -.- -..-", "Fourth Test"
print("Coding complete? Click 'Check' to earn cool rewards!")
Jan. 3, 2019