Solution to problem 19 part 2 in Python

This commit is contained in:
David Doblas Jiménez 2022-01-17 20:28:14 +01:00
parent 092c9683d9
commit 1bc00c12fe

View File

@ -89,7 +89,7 @@ with open("files/P19.txt", "r") as f:
rules, messages = [f.split("\n") for f in f.read().strip().split("\n\n")]
def dfs(tree: dict[int, int], node: str, depth: int) -> str:
def dfs(tree, node, depth):
if depth > 15:
return ""
rule = ""
@ -103,7 +103,7 @@ def dfs(tree: dict[int, int], node: str, depth: int) -> str:
return "(" + rule + ")"
def part_1() -> None:
def part_1():
rules_dict = dict([rule.split(": ") for rule in rules])
rule_0 = re.compile(dfs(rules_dict, "0", 0))
total = sum([1 for message in messages if rule_0.fullmatch(message)])