-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday9pt1.py
59 lines (46 loc) · 1.19 KB
/
day9pt1.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from day9input import day9input
index = 0
empty_char = '.'
index_toggle = True
count_string = day9input
def check_current_count(count):
global index_toggle
global index
destructured_list = []
for i in range(0, count):
if index_toggle:
destructured_list.append(str(index))
# print(str(index))
else:
destructured_list.append(empty_char)
# print(empty_char)
if index_toggle:
index += 1
index_toggle = not index_toggle
return destructured_list
print(count_string)
destructured_all = []
for count in list(count_string):
destruct_list = check_current_count(int(count))
print(destruct_list)
destructured_all += destruct_list
i = 0
j = len(destructured_all) - 1
while (j > i ):
#
# print(destructured_all[i])
# print(destructured_all[j])
if destructured_all[i] == '.' and destructured_all[j] != '.':
[destructured_all[i], destructured_all[j]] = [destructured_all[j], destructured_all[i]]
if destructured_all[i] != '.':
i +=1
if destructured_all[j] == '.':
j -=1
#
# print(i, j)
# print(destructured_all)
checksum = 0
for dest_i in range(len(destructured_all)):
if destructured_all[dest_i] == '.': break
checksum += int(destructured_all[dest_i]) * dest_i
print(checksum)