Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Morse Clock by Bilou06
# migrated from python 2.7
def checkio(data):
#normalize string with zeros
data = ':'.join( [x.zfill(2) for x in data.split(':')] )
def toDots( index ):
if data[index] == ':':
return ':'
length = [2, 4, 0, 3, 4, 0, 3, 4][index]
return bin(int(data[index]))[2:].zfill(length).replace('0', '.').replace('1', '-')
return ' '.join(map(toDots, list(range(8))))
#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"
July 19, 2013