You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12 lines
328 B

input = open("input.txt", 'r').read().splitlines()
instructions = input[0]
nodes = {l.split()[0]: (l.split()[2][1:-1], l.split()[3][:-1]) for l in input[2:]}
steps = 0
node = 'AAA'
while node != 'ZZZ':
node = nodes[node][0] if instructions[steps % len(instructions)] == 'L' else nodes[node][1]
steps += 1
print(steps)