29 lines
641 B
Python
29 lines
641 B
Python
#!/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)
|