83 lines
1.7 KiB
Python
83 lines
1.7 KiB
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')
|
|
|
|
d = list(d)
|
|
|
|
s = []
|
|
l = []
|
|
r = []
|
|
|
|
maps = maps
|
|
|
|
nmaps = []
|
|
|
|
for i in maps:
|
|
if i == '':
|
|
continue
|
|
s = i[:3]
|
|
l = i[7:10]
|
|
r = i[12:15]
|
|
nmaps.append([s,l,r])
|
|
|
|
|
|
#pprint(d)
|
|
#pprint(maps)
|
|
#pprint(nmaps)
|
|
|
|
count = 0
|
|
way = 'AAA'
|
|
first = True
|
|
found = False
|
|
index = 0
|
|
#print('Starting with ' + way)
|
|
cycle = 0
|
|
while found == False:
|
|
cycle += 1
|
|
for idx, i in enumerate(d):
|
|
#print(way)
|
|
#print('Finding Index for ' + way,end=' at ')
|
|
c = way
|
|
#if first == False:
|
|
index = [(i,table.index(c)) for i, table in enumerate(nmaps) if c in table]
|
|
#print(index,end='')
|
|
for j in index:
|
|
if list(j)[1] == 0:
|
|
index = list(j)[0]
|
|
#index = list(index[0])[1]
|
|
#print(' (true index ',end='')
|
|
#print(index,end=') ')
|
|
#else:
|
|
# first = False
|
|
if i == 'R':
|
|
way = nmaps[index][2]
|
|
#print('Going R to ' + way)
|
|
if i == 'L':
|
|
way = nmaps[index][1]
|
|
#print('Going L to ' + way)
|
|
count += 1
|
|
if way == 'ZZZ':
|
|
found = True
|
|
#print('COUND')
|
|
continue
|
|
#if nmaps[index][1] == 'ZZZ' or nmaps[index][2] == 'ZZZ':
|
|
# print(nmaps[index][1],nmaps[index][2])
|
|
# print('Found at ' + str(index) + ' with count ' + str(count))
|
|
# found = True
|
|
# continue
|
|
print('Result: ' + str(count))
|