Day 23
This commit is contained in:
1
day23/input.txt
Normal file
1
day23/input.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
952316487
|
||||||
19
day23/part1.py
Normal file
19
day23/part1.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from functools import reduce
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
|
num = [list(map(int, (char for char in x.strip()))) for x in open("input.txt")][0]
|
||||||
|
|
||||||
|
for _ in tqdm(range(100)):
|
||||||
|
destination = num[0]
|
||||||
|
while True:
|
||||||
|
destination -= 1
|
||||||
|
if destination == 0:
|
||||||
|
destination = 9
|
||||||
|
if not destination in num[1:4]:
|
||||||
|
break
|
||||||
|
pos = num.index(destination)
|
||||||
|
num = num[4:pos+1] + num[1:4] + num[pos+1:] + num[0:1]
|
||||||
|
|
||||||
|
pos = num.index(1)
|
||||||
|
print(reduce(lambda a, b: 10*a+b, num[pos+1:] + num[:pos], 0))
|
||||||
52
day23/part2.py
Normal file
52
day23/part2.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
|
|
||||||
|
class Node:
|
||||||
|
value = None
|
||||||
|
next = None
|
||||||
|
|
||||||
|
def __init__(self, value, next):
|
||||||
|
self.value = value
|
||||||
|
self.next = next
|
||||||
|
|
||||||
|
|
||||||
|
num = [list(map(int, (char for char in x.strip()))) for x in open("input.txt")][0]
|
||||||
|
num = num + list(range(len(num)+1, 1000000+1))
|
||||||
|
MAX = len(num)
|
||||||
|
|
||||||
|
nodes = dict()
|
||||||
|
nodes[num[-1]] = curr = last = Node(num[-1], None)
|
||||||
|
for n in num[-2::-1]:
|
||||||
|
nodes[n] = curr = Node(n, curr)
|
||||||
|
last.next = curr
|
||||||
|
|
||||||
|
for _ in tqdm(range(10000000)):
|
||||||
|
pickups = []
|
||||||
|
lp = curr
|
||||||
|
for j in range(3):
|
||||||
|
lp = lp.next
|
||||||
|
pickups.append(lp.value)
|
||||||
|
ap = lp.next
|
||||||
|
|
||||||
|
destination = curr.value
|
||||||
|
while True:
|
||||||
|
destination -= 1
|
||||||
|
if destination == 0:
|
||||||
|
destination = MAX
|
||||||
|
if destination not in pickups:
|
||||||
|
break
|
||||||
|
dst = nodes[destination]
|
||||||
|
lp.next = dst.next
|
||||||
|
dst.next = curr.next
|
||||||
|
curr.next = ap
|
||||||
|
curr = curr.next
|
||||||
|
|
||||||
|
while curr.value != 1:
|
||||||
|
curr = curr.next
|
||||||
|
curr = curr.next
|
||||||
|
res = curr.value
|
||||||
|
curr = curr.next
|
||||||
|
res *= curr.value
|
||||||
|
|
||||||
|
print(res)
|
||||||
Reference in New Issue
Block a user