AdventOfCode2023/day8-1.py

44 lines
917 B
Python
Raw Normal View History

2023-12-10 16:54:38 -06:00
with open("input_day8.txt") as file:
lines = [line.rstrip() for line in file]
#unused bc i am so cool
class seq:
def __init__(self,name,left,right):
self.name = name
self.left = left
self.right = right
turns = lines[0]
sequences = lines[2:]
left_dict = {}
right_dict = {}
for a in sequences:
name = a.split(" ")[0]
left = a.split(" ")[2][1:4]
right = a.split(" ")[3][0:3]
left_dict[name] = left
right_dict[name] = right
i = 0
total = 0
cur_name = "AAA"
alive = True
while alive:
if cur_name == "ZZZ":
alive = False
else:
if turns[i] == 'L':
next_node_name = left_dict[cur_name]
else:
next_node_name = right_dict[cur_name]
cur_name = next_node_name
i+=1
if i>=len(turns):
i = 0
total+=1
print(total)