advent_of_code/2023/8/8.py

30 lines
641 B
Python
Raw Permalink Normal View History

2023-12-19 21:32:15 +01:00
#!/usr/bin/env python
# 2023 - Advent Of Code 8
# file = 'input_example.txt'
file = 'input.txt'
# pylint: disable=consider-using-with
input_lines = [line.strip('\n') for line in open(file, encoding="utf-8")]
directions = input_lines[0]
print(directions)
nodes = {}
for l in input_lines[2:]:
k, v = l.split(' = ')
nodes[k] = v[1:-1].split(', ')
cur_node = 'AAA'
count = 0
while cur_node != 'ZZZ':
# print(cur_node)
if directions[count % len(directions)] == 'L':
cur_node = nodes[cur_node][0]
elif directions[count % len(directions)] == 'R':
cur_node = nodes[cur_node][1]
count += 1
print(count)