forked from n00blet/CheckIO-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMorseClock.py
More file actions
25 lines (21 loc) · 822 Bytes
/
Copy pathMorseClock.py
File metadata and controls
25 lines (21 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def checkio(data):
code =[]
for i, d in enumerate(data.split(':')):
d=int(d)
y=''
f=d/10
s=d%10
if i==0:
y+='{0:02b} '.format(f)
else:
y+='{0:03b} '.format(f)
y+='{0:04b}'.format(s)
code.append(y)
code=' : '.join(code)
return code.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("00:1:02") == ".. .... : ... ...- : ... ..-.", "Third Test"
assert checkio("23:59:59") == "-. ..-- : -.- -..- : -.- -..-", "Fourth Test"