Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Morse Clock by Rafal.U
def checkio(time_string):
def binarne(cyfra, dlugosc): # funkcja binarne zamienia cyfre w reprezentacje binarna
return bin(cyfra)[2:2+dlugosc].zfill(dlugosc)
def morse(cyfra_bin): # funkcja morse zamienia 0 i 1 w ciagu binarnym na "." i "-"
return cyfra_bin.replace('0', '.').replace('1', '-')
godzina = time_string.split(":") # tworzy liste stringów z cyfr które na wejsciu sa oddzielone znakiem ":"
h = int(godzina[0]) # przekonwertowanie stringów na liczby całkowite i przypisanie do zmiennych h,m,s
m = int(godzina[1])
s = int(godzina[2])
h1, h2 = (h // 10) % 10, h % 10 # przypisanie do zmiennych odpowiednio pierwszej i drugiej cyfry liczb dwucyfrowych
m1, m2 = (m // 10) % 10, m % 10
s1, s2 = (s // 10) % 10, s % 10
h1, h2 = binarne(h1, 2), binarne(h2, 4) # wywołanie funkcji
m1, m2 = binarne(m1, 3), binarne(m2, 4)
s1, s2 = binarne(s1, 3), binarne(s2, 4)
h1, h2 = morse(h1), morse(h2) # wywołanie funkcji
m1, m2 = morse(m1), morse(m2)
s1, s2 = morse(s1), morse(s2)
return "%s %s : %s %s : %s %s" % (h1, h2, m1, m2, s1, s2)
#replace this for solution
return ".- .... : .-- .--- : -.. -..-"
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"
Jan. 16, 2017