Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by Luker
def checkio(time_string):
time=""
a=0
if len(time_string)==8:
time=time_string
else:
for i in range(len(time_string)):
a=a+1
if i!=len(time_string)-1:
if time_string[i+1]==':' and a<2:
time=time+'0'
else:
if a<2:
time=time+'0'
if time_string[i]==':':
a=0
time=time+time_string[i]
print(time)
b=1
c=0
result=""
temp=[]
for i in time:
if i==':':
temp.append(8)
b=b+1
continue
c=int(i)
c=bin(c)
c=c[2:]
a=[]
for j in c:
if j=='1':
a.append(1)
if j=='0':
a.append(0)
print(a)
a.reverse()
if b==1:
if len(a)<2:
a.append(0)
if b==4 or b==7:
for j in range(2):
if len(a)<3:
a.append(0)
if b==2 or b==5 or b==8:
for j in range(3):
if len(a)<4:
a.append(0)
a.reverse()
temp=temp+a
temp.append(9)
print (temp)
b=b+1
temp.pop()
for i in temp:
if i==1:
result=result+'-'
if i==0:
result=result+'.'
if i==8:
result=result+': '
if i==9:
result=result+' '
print(result)
return result
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio(u"10:37:49") == ".- .... : .-- .--- : -.. -..-", "First Test"
assert checkio(u"21:34:56") == "-. ...- : .-- .-.. : -.- .--.", "Second Test"
assert checkio(u"00:1:02") == ".. .... : ... ...- : ... ..-.", "Third Test"
assert checkio(u"23:59:59") == "-. ..-- : -.- -..- : -.- -..-", "Fourth Test"
Nov. 13, 2016