Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by Machinero
def change(bin_number):
return bin_number.replace("0",".").replace("1","-")
def checkio(time_string):
test = time_string.split(":")
for i in range(len(test)):
if int(test[i]) < 10:
test[i] = test[i].zfill(2)
result = " ".join(test)
h1,h2 = change(format(int(result[0]), 'b').zfill(2)), change(format(int(result[1]), 'b').zfill(4))
m1,m2 = change(format(int(result[3]), 'b').zfill(3)), change(format(int(result[4]), 'b').zfill(4))
s1,s2 = change(format(int(result[6]), 'b').zfill(3)), change(format(int(result[7]), 'b').zfill(4))
return "%s %s : %s %s : %s %s" % (h1,h2,m1,m2,s1,s2)
#replace this
return ".- .... : .-- .--- : -.. -..-"
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"
Dec. 17, 2016