Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by H4stoor
def checkio(time_string):
_bin = lambda x: bin(int(x))[2:]
hours, minutes, seconds = [elem.zfill(2) for elem in time_string.split(':')]
hours = '{:0>2} {:0>4}'.format(*[_bin(i) for i in hours])
minutes = '{:0>3} {:0>4}'.format(*[_bin(i) for i in minutes])
seconds = '{:0>3} {:0>4}'.format(*[_bin(i) for i in seconds])
return ' : '.join([hours, minutes, seconds]).replace('0', '.').replace('1', '-')
if __name__ == '__main__':
#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("DONE")
Jan. 12, 2018