Files
python-aoc-2023/day08/part1.py
Sebastian Seedorf aaecd0a396 Day 08
2023-12-08 13:25:45 +01:00

19 lines
395 B
Python

#!/usr/bin/env python3
lines = (x.strip() for x in open("input.txt"))
instructions = tuple(int(char == "R") for char in next(lines))
next(lines)
nodes = {line[:3]: (line[7:10], line[12:15]) for line in lines}
node = "AAA"
cnt = 0
while True:
for char in instructions:
node = nodes[node][char]
cnt += 1
if node == "ZZZ":
print(cnt)
exit(0)