Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by Rcp8jzd
def get_bin(x, n):
""" Returns the n bits binary representation of an integer """
return format(x, 'b').zfill(n)
def checkio(time_string: str) -> str:
time_int = time_string.split(':')
time_int = [int(string) for string in time_int]
time_digit = [[elt // 10, elt % 10] for elt in time_int]
n_bits = [[2, 4], [3, 4], [3, 4]]
# Convert ints to binary with above function
time_bytes = [[get_bin(time_digit[i][j], n_bits[i][j]) for j in range(2)]
for i in range(3)]
time_bytes = " : ".join(" ".join(elt) for elt in time_bytes)
time_morse = time_bytes.replace('0', '.').replace('1', '-')
return time_morse
Feb. 19, 2020