Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Uncategorized category for Morse Clock by choz
def checkio(data):
#After viewing the other solutions with the magic function zfill :)
data=[un.zfill(2) for un in data.split(':')]
r=[bin(int(data[idx][0]))[2:].zfill(un)+" "+bin(int(data[idx][1]))[2:].zfill(4) for idx, un in enumerate([2, 3, 3])]
return " : ".join(r).replace('0', '.').replace('1', '-')
#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. 2, 2013