Working on 2023-12-08 p1

This commit is contained in:
FrederikBaerentsen 2023-12-08 09:55:45 +01:00
parent 27f66da8f8
commit b6ae910775
3 changed files with 95 additions and 0 deletions

81
2023/day8/part1.py Normal file
View File

@ -0,0 +1,81 @@
#!/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 = nmaps[0][0]
first = True
found = False
index = 0
print('Starting with ' + way)
while found == False:
for i in d:
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
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
# input()
print(count)

5
2023/day8/test2 Normal file
View File

@ -0,0 +1,5 @@
LLR
AAA = (BBB, BBB)
BBB = (AAA, ZZZ)
ZZZ = (ZZZ, ZZZ)

9
2023/day8/test3 Normal file
View File

@ -0,0 +1,9 @@
RLLRLRLRRLRLRLRLRL
AAA = (BBB, CCC)
BBB = (DDD, EEE)
CCC = (ZZZ, GGG)
DDD = (DDD, DDD)
EEE = (EEE, EEE)
GGG = (GGG, GGG)
ZZZ = (ZZZ, ZZZ)