summaryrefslogtreecommitdiff
path: root/08/main.py
blob: bcbd2dd6d1f9d5d33c02eb1152e28ee962616bfd (plain)
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
#!/bin/python3
import sys
import re

route = [("L", "R").index(x) for x in input().strip()]
map = {}
for line in sys.stdin:
  line = line.strip()
  if len(line) == 0: continue

  line = re.sub("[^A-Z]+", " ", line)
  location, left, right = line.split()

  map[location] = (left, right,)

START = "AAA"
DESTINATION = "ZZZ"

steps = 0
current_location = START
while current_location != DESTINATION:
  route_idx = steps % len(route)
  steps += 1
  current_location = map[current_location][route[route_idx]]

print(f">> {steps}")