Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by darasg2008
def checkio(time_string):
#filling missing digits
if time_string[1]==':':
time_string='0'+time_string
if time_string[4]==':':
time_string=time_string[:3]+'0'+time_string[3:]
if len(time_string)==7:
time_string=time_string[:6]+'0'+time_string[6]
morse=""
i=0
ind=[2,8,0,4,8,0,4,8]
for c in time_string:
if c==':':
morse=morse+': '
i+=1
continue
a=int(c)
b=ind[i]
i+=1
while a>0 or b>0:
if a>=b:
morse=morse+'-'
a=a-b
b=b//2
else:
morse=morse+'.'
b=b//2
morse=morse+' '
return morse[:-1]
Nov. 4, 2016