Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Morse Clock by Moonra
def checkio(data):
hours, minutes, seconds = (int(x) for x in data.split(":"))
dozen_hours_digits = '{0:02b}'.format(hours//10)
unit_hours_digits = '{0:04b}'.format(hours%10)
dozen_minutes_digits = '{0:03b}'.format(minutes//10)
unit_minutes_digits = '{0:04b}'.format(minutes%10)
dozen_seconds_digits = '{0:03b}'.format(seconds//10)
unit_seconds_digits = '{0:04b}'.format(seconds%10)
result = "{0} {1} : {2} {3} : {4} {5}".format(dozen_hours_digits, unit_hours_digits, dozen_minutes_digits, unit_minutes_digits, dozen_seconds_digits, unit_seconds_digits)
return result.replace("0", ".").replace("1", "-")
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio("10:37:49") == ".- .... : .-- .--- : -.. -..-", "First Test"
assert checkio("21:34:56") == "-. ...- : .-- .-.. : -.- .--.", "Second Test"
assert checkio("11:10:12") == ".- ...- : ..- .... : ..- ..-.", "Third Test"
assert checkio("23:59:59") == "-. ..-- : -.- -..- : -.- -..-", "Fourth Test"
July 19, 2013
Comments: