Continue with 2016 and 2017.

This commit is contained in:
2024-05-04 09:25:24 -04:00
parent 6e0cd511cc
commit 29ab4f3496
6 changed files with 479 additions and 1 deletions

45
2016/d15.py Normal file
View File

@@ -0,0 +1,45 @@
import sys
from lib import str_to_ints
from copy import deepcopy
with open("i15.txt") as f:
d = f.read()
part_2 = True
if part_2:
d += "#7 11 0 0"
discs = []
for line in d.splitlines():
id, npos, time, cpos = str_to_ints(line)
discs.append([cpos, npos])
qpos = -1
orig_discs = deepcopy(discs)
# empirically could dev algo to find or CRT?
if part_2:
start, delta = 12136, 33915
else:
start, delta = 831, 2261
for start_time in range(start, 1_000_000_000, delta):
discs = deepcopy(orig_discs)
# let discs move for initial wait
for _ in range(start_time):
for disc in discs:
disc[0] = (disc[0] + 1) % disc[1]
# drop the capsule
for i in range(len(discs)):
# discs move first
for disc in discs:
disc[0] = (disc[0] + 1) % disc[1]
# check if there is a collission for the current disc
if discs[i][0] != 0:
break
else:
print(start_time)
sys.exit(0)