-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday16.py
More file actions
36 lines (24 loc) · 737 Bytes
/
day16.py
File metadata and controls
36 lines (24 loc) · 737 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
25
26
27
28
29
30
31
32
33
34
35
36
data = '10111100110001111'
disc_size = 272
disc_size = 35651584
def generate_data(data_: str):
data_new = data_[::-1]
data_new = data_new.replace('1', '_')
data_new = data_new.replace('0', '1')
data_new = data_new.replace('_', '0')
return data_ + '0' + data_new
while len(data) < disc_size:
data = generate_data(data)
data = data[:disc_size]
def generate_checksum(checksum_):
checksum_new = ''
for a, b in zip(checksum_[::2], checksum_[1::2]):
if a == b:
checksum_new += '1'
else:
checksum_new += '0'
return checksum_new
checksum = data
while len(checksum) % 2 == 0:
checksum = generate_checksum(checksum)
print('Checksum: {}'.format(checksum))