day8 part 2 work in progress, still not working

This commit is contained in:
2023-12-09 08:28:09 +01:00
parent 3d1582f685
commit 7b73d8402a
5 changed files with 107 additions and 29 deletions

View File

@@ -39,8 +39,12 @@ class Node:
def is_A_node(self):
return self.value[2] == 'A'
def is_Z_node(self):
return self.value[2] == 'Z'
def __str__(self):
return f"{self.value} = ({self.left}, {self.right})"
def parse(input_file:str) -> Tuple[str, List[Node]]:
@@ -48,7 +52,7 @@ def parse(input_file:str) -> Tuple[str, List[Node]]:
with open(input_file) as input:
directions = input.readline().replace("\n","")
_ = input.readline()
while match:= re.match("([A-Z]+) = \(([A-Z]+), ([A-Z]+)\)",input.readline()):
while match:= re.match("([A-Z]+) = \(([A-Z]+), ([A-Z]+)\)", input.readline()):
node = Node(value=match.group(1), left=match.group(2), right=match.group(3))
the_list.append(node)
return directions, the_list