Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple solution solution in Clear category for Morse Clock by caldeius
def checkio(time_string: str) -> str:
#converting hms to hhmmss
time_string = ':'.join([hms.rjust(2,'0') for hms in time_string.split(':')])
# length of morse to return
lng = [2,4,3,4,3,4]
# form : gives position of séparators ' :' to add
form = [0,1,0,1,0,0]
binary_digits = [format(int(i), 'b') for i in time_string if i.isnumeric() ]
padded_digits = [digit.rjust(lng[pos],'0') for pos, digit in enumerate(binary_digits )]
binary_time = ' '.join([digit + ' :' if form[pos] == 1 else digit for pos, digit in enumerate(padded_digits)])
return(binary_time.replace('0','.').replace('1','-'))
if __name__ == '__main__':
print("Example:")
print(checkio("10:37:49"))
#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"
print("Coding complete? Click 'Check' to earn cool rewards!")
Jan. 22, 2020
Comments: