Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Morse Clock by jabuci
def checkio(data):
h, m, s = data.split(":")
text = h.zfill(2) + m.zfill(2) + s.zfill(2)
#
fill = [2,4,3,4,3,4]
res = []
for index, val in enumerate(text):
binary = bin(int(val)).lstrip('0b').zfill(fill[index])
res.append(binary.replace('1', '-').replace('0', '.'))
return "{} {} : {} {} : {} {}".format(*res)
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio("10:37:49") == ".- .... : .-- .--- : -.. -..-", "First Test"
assert checkio("21:34:56") == "-. ...- : .-- .-.. : -.- .--.", "Second Test"
assert checkio("11:10:12") == ".- ...- : ..- .... : ..- ..-.", "Third Test"
assert checkio("23:59:59") == "-. ..-- : -.- -..- : -.- -..-", "Fourth Test"
Aug. 19, 2013