Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Morse Clock by MedykMatyk
def morse_converter(character, isFirst, minLength):
test = int(character)
result = ""
for i in range(3,-1,-1):
if(test>=2**i):
test-=2**i
result +='-'
else:
result+='.'
#print ("Convertion result for" + character + " before edit: " + result)
if(isFirst==1):
for i in range(1, minLength):
if(result[0]=='.' and '.' in result[1:]):
result = result[1:]
print ("Convertion result for" + character + ": " + result)
return result
def checkio(time_string):
minLength = 3
result =""
isFirst = True
for i in range(0,len(time_string)):
if(time_string[i]!=':'):
if(isFirst):
if(len(time_string)>i+1):
if(time_string[i+1]==':' and i!=0):
result += '... '
isFirst=False
elif(i==0 and time_string[i+1]==':'):
result += '.. '
isFirst=False
else:
if(time_string[i-1]==':' and i!=0):
result += '... '
isFirst=False
elif(i==0):
result += '.. '
isFirst=False
result += morse_converter(time_string[i], isFirst,minLength)
isFirst=False
minLength=2
else:
result += ' ' +morse_converter(time_string[i], isFirst, minLength)
isFirst=True
else:
result += ' : '
isFirst=True
print("Final result: " + result)
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"
Nov. 7, 2017