aoc2023/d08/run1.py

27 lines
439 B
Python
Raw Permalink Normal View History

2024-06-07 01:12:49 +00:00
import sys
from itertools import cycle
L = sys.stdin.read().splitlines()
N = L[2:]
M = []
for x in N:
(a, b) = x.split(" = ")
c = b.split(", ")
M.append( (a, c[0].replace("(", ""), c[1].replace(")", "")) )
S = 0
tri = "AAA"
for i in cycle(L[0]) :
for a, b, c in M:
if a == tri:
#print(a, b, c)
tri = b if i == "L" else c
break
S+=1
if tri == "ZZZ" : break
print(S)