aoc2023/d08/part1.py

24 lines
362 B
Python
Raw Normal View History

import sys
from itertools import cycle
L = [l for l in sys.stdin.read().splitlines()]
I = L[0] # instructions
for l in L[2:]:
print(f'%{l}%')
Q = [l.split(' = ') for l in L[2:] ]
P = {k:v[1:-1].split(", ") for [k,v] in Q }
print(P)
C = 'AAA'
N = 0
for i in cycle(I):
if C == 'ZZZ':
break
C = P[C][i == 'R']
N += 1
print(C)
print(N)