-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathday_23b.py
57 lines (50 loc) · 1.58 KB
/
day_23b.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
#!/usr/bin/python3
def main():
highest_element = 1000000
n_rounds = 10000000
n_lift = 3
f = open("../input/day_23_input")
line = f.readline().strip("\n")
order_list = list()
for char in line:
order_list.append(int(char))
order = dict()
for i in range(0, len(order_list) - 1):
order[order_list[i]] = order_list[i + 1]
order[order_list[-1]] = len(order_list) + 1
i = len(order_list) + 1
while i <= highest_element:
order[i] = i + 1
i = i + 1
order[len(order)] = order_list[0]
current_cup = order_list[0]
low = min(order_list)
high = highest_element
for round in range(0, n_rounds):
remove_first = order[current_cup]
current_now_connected_to = current_cup
lifting = list()
for _ in range(0, n_lift + 1):
current_now_connected_to = order[current_now_connected_to]
if len(lifting) != n_lift:
lifting.append(current_now_connected_to)
order[current_cup] = current_now_connected_to
dest_cup = current_cup - 1
if dest_cup < low:
dest_cup = high
while dest_cup in lifting:
dest_cup = dest_cup - 1
if dest_cup < low:
dest_cup = high
temp = order[dest_cup]
order[dest_cup] = remove_first
val = remove_first
for _ in range(0, n_lift - 1):
val = order[val]
order[val] = temp
current_cup = order[current_cup]
ans = order[1] * order[order[1]]
print(ans)
return ans
if __name__ == "__main__":
main()