-
Notifications
You must be signed in to change notification settings - Fork 0
/
08_part1.py
36 lines (28 loc) · 883 Bytes
/
08_part1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from collections import deque
directions = input()
directions_queue = deque(directions)
positions = {}
current_position = input()
while current_position != "stop":
if current_position == "":
current_position = input()
continue
key = current_position.split(" = ")[0]
value = current_position.split(" = ")[1].split(", ")
positions[key] = [value[0].strip("("), value[1].strip(")")]
current_position = input()
starting_key = "AAA"
ending_key = "ZZZ"
step_counter = 0
while True:
current_direction = directions_queue[0]
if current_direction == "R":
starting_key = positions[starting_key][1]
else:
starting_key = positions[starting_key][0]
step_counter += 1
directions_queue.popleft()
directions_queue.append(current_direction)
if starting_key == ending_key:
break
print(step_counter)