62 lines
924 B
Python
62 lines
924 B
Python
#!/bin/python3
|
|
|
|
import re
|
|
import sys
|
|
from pprint import pprint
|
|
from collections import Counter
|
|
import numpy as np
|
|
|
|
input_f = sys.argv[1]
|
|
|
|
def pp(x):
|
|
for i in x:
|
|
for j in i:
|
|
print(j)
|
|
print()
|
|
|
|
d, *maps = open(input_f).read().split('\n')
|
|
|
|
|
|
class Node():
|
|
def __init__(self,value,left,right):
|
|
self.value = value
|
|
self.left = left
|
|
self.right = right
|
|
|
|
s = []
|
|
l = []
|
|
r = []
|
|
|
|
maps = maps
|
|
|
|
nodes = {}
|
|
|
|
for i in maps:
|
|
if i == '':
|
|
continue
|
|
s = i[:3]
|
|
l = i[7:10]
|
|
r = i[12:15]
|
|
nodes[s] = Node(s,l,r)
|
|
|
|
current = 'AAA'
|
|
steps = 0
|
|
count = 0
|
|
try:
|
|
while current != 'ZZZ':
|
|
steps += 1
|
|
current = nodes[current].left if d[count%len(d)] == 'L' else nodes[current].right
|
|
count += 1
|
|
print(steps)
|
|
except:
|
|
print()
|
|
|
|
|
|
current = {}
|
|
for i in nodes:
|
|
if i.endswith('A'):
|
|
current[i] = i
|
|
|
|
#while not current.endswith('Z'):
|
|
|