114 lines
1.8 KiB
Python
114 lines
1.8 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')
|
|
|
|
|
|
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
|
|
|
|
way = []
|
|
|
|
for i in nmaps:
|
|
if i[0].endswith('A'):
|
|
way.append(i[0])
|
|
|
|
print(way)
|
|
|
|
cycles = []
|
|
|
|
print(d)
|
|
|
|
for cur in way:
|
|
cycle = []
|
|
|
|
count = 0
|
|
cur_d = d
|
|
|
|
while True:
|
|
while count == 0 or not cur.endswith('Z'):
|
|
|
|
|
|
count += 1
|
|
|
|
index = [(i,table.index(cur)) for i, table in enumerate(nmaps) if cur in table]
|
|
|
|
for j in index:
|
|
if list(j)[1] == 0:
|
|
index = list(j)[0]
|
|
if cur_d[0] == 'R':
|
|
cur = nmaps[index][2]
|
|
if cur_d[0] == 'L':
|
|
cur = nmaps[index][1]
|
|
|
|
|
|
print(cur)
|
|
|
|
cur_d = cur_d[1:] + cur_d[0]
|
|
|
|
print(cur_d)
|
|
input()
|
|
|
|
cycle.append(count)
|
|
cycles.append(cycle)
|
|
|
|
|
|
|
|
print(cycles)
|
|
|
|
"""
|
|
while found == False:
|
|
i = d[count%len(d)]
|
|
c = way
|
|
index = [(i,table.index(c)) for i, table in enumerate(nmaps) if c in table]
|
|
for j in index:
|
|
if list(j)[1] == 0:
|
|
index = list(j)[0]
|
|
if i == 'R':
|
|
way = nmaps[index][2]
|
|
if i == 'L':
|
|
way = nmaps[index][1]
|
|
count += 1
|
|
if way == 'ZZZ':
|
|
found = True
|
|
continue
|
|
"""
|
|
print('Result: ' + str(count))
|