AdventOfCode/2023/day8/part2.py

55 lines
757 B
Python
Raw Normal View History

2023-12-08 12:36:03 +01:00
#!/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')
2023-12-08 13:26:14 +01:00
class Node():
def __init__(self,value,left,right):
self.value = value
self.left = left
self.right = right
2023-12-08 12:36:03 +01:00
s = []
l = []
r = []
maps = maps
2023-12-08 13:26:14 +01:00
nodes = {}
2023-12-08 12:36:03 +01:00
for i in maps:
if i == '':
continue
s = i[:3]
l = i[7:10]
r = i[12:15]
2023-12-08 13:26:14 +01:00
nodes[s] = Node(s,l,r)
2023-12-08 12:36:03 +01:00
2023-12-08 13:26:14 +01:00
pprint(nodes)
2023-12-08 12:36:03 +01:00
2023-12-08 13:26:14 +01:00
current = 'AAA'
steps = 0
2023-12-08 12:36:03 +01:00
index = 0
2023-12-08 13:26:14 +01:00
directions = d
while current != 'ZZZ':
steps += 1
directions = directions[index]
if directions == 'L':
2023-12-08 12:36:03 +01:00
2023-12-08 13:26:14 +01:00
print(steps)