Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by wojtek96
def checkio(data):
h,m,s = map(int,data.split(":"))
h1,h2 = (h//10)%10,h%10
m1,m2 = (m//10)%10,m%10
s1,s2 = (s//10)%10,s%10
dh = 2
dms = 3
d2 = 4
def ful(x,d):
s=""
for i in range (d-(len(x)-2)):
s = s + "0"
s = s + x[2:]
return s
h1,h2,m1,m2,s1,s2 = ful(bin(h1),dh),ful(bin(h2),d2),ful(bin(m1),dms),ful(bin(m2),d2),ful(bin(s1),dms),ful(bin(s2),d2)
result = h1 + " " + h2 + " : " + m1 + " " + m2 + " : " + s1 + " " + s2
result = result.replace("0",".")
result = result.replace("1","-")
return result
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. 15, 2016