Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Morse Clock by htamas
def checkio(data):
h, m, s = map(int, data.split(':'))
patterns = ['....', '...-', '..-.', '..--', '.-..', '.-.-', '.--.', '.---', '-...', '-..-']
a = patterns[h//10][-2:] + ' ' + patterns[h%10] + ' : '
a += patterns[m//10][-3:] + ' ' + patterns[m%10] + ' : '
a += patterns[s//10][-3:] + ' ' + patterns[s%10]
return a
#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("00:1:02") == ".. .... : ... ...- : ... ..-.", "Third Test"
assert checkio("23:59:59") == "-. ..-- : -.- -..- : -.- -..-", "Fourth Test"
Oct. 19, 2013
Comments: