adventOfCode/2023/8/part1.py
Daniel Bulant 5a88d559b5 day 8
2023-12-08 11:55:00 +01:00

23 lines
No EOL
575 B
Python

instructions = []
nodes = {}
for line in open("./input2"):
if not instructions:
instructions = [x for x in line.strip()]
continue
if line == "\n": continue
name = line.split(" ")[0].strip()
leftnode = line.split("(")[1].split(",")[0].strip()
rightnode = line.split("(")[1].split(",")[1].split(")")[0].strip()
nodes[name] = (leftnode, rightnode)
node = "AAA"
count = 0
while node != "ZZZ":
node = nodes[node][1 if instructions[0] == "R" else 0]
instructions = instructions[1:] + instructions[:1]
count += 1
print(count)