day 8, generators are faster (2x)

This commit is contained in:
2025-09-08 16:38:35 +02:00
parent d165384617
commit e58ddb9f96

22
d08/run.py Normal file
View File

@@ -0,0 +1,22 @@
import sys
from itertools import cycle
from math import lcm
I, _, *P = [l for l in sys.stdin.read().splitlines()]
# 0000000000111111111
# 0123456789012345678
# BCN = (HFN, KFC)
P = {l[0:3]:(l[7:10],l[12:15]) for l in P}
def countsteps(g):
C = g
N = 0
for i in cycle(I):
if C[2] == 'Z':
break
C = P[C][i == 'R']
N += 1
return N
print("part 1:", countsteps("AAA"))
print("part 2:", lcm(*(countsteps(p) for p in P.keys() if p[2] == 'A')))