Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by PythOff
def morseDigit (dig):
res = ""
while dig > 0:
if dig%2:
res = '-' + res
else:
res = '.' + res
dig //= 2
return res
def morseNum (num, len1, len2):
return morseDigit(num//10).rjust(len1, '.') + ' ' + morseDigit(num%10).rjust(len2, '.')
def checkio(time_string):
idx1 = time_string.index(':')
idx2 = time_string[idx1+1:].index(':') + idx1 + 1
sHH = int(time_string[0:idx1])
sMM = int(time_string[idx1+1:idx2])
sSS = int(time_string[idx2+1:])
#print (morseNum(sHH, 2, 4) + ' : ' + morseNum(sMM, 3, 4) + ' : ' + morseNum(sSS, 3, 4))
return (morseNum(sHH, 2, 4) + ' : ' + morseNum(sMM, 3, 4) + ' : ' + morseNum(sSS, 3, 4))
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. 4, 2016