diff --git a/day19/part1.py b/day19/part1.py index 88eff2b..ca0b65f 100644 --- a/day19/part1.py +++ b/day19/part1.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import re lines = (x.strip() for x in open("input.txt")) rules = {} diff --git a/day19/part2.py b/day19/part2.py index c32f2ad..7dc980f 100644 --- a/day19/part2.py +++ b/day19/part2.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import re lines = (x.strip() for x in open("input.txt")) rules = {} @@ -15,19 +14,20 @@ def yield_rule(line, rule, depth): def check(line, idx, depth=0): - if depth <= 100: - rs = rules[idx] - if isinstance(rs, str): - if line.startswith(rs): - yield line[len(rs):] - else: - for rule in rules[idx]: - yield from yield_rule(line, rule, depth) + if depth > 100: + return + rs = rules[idx] + if isinstance(rs, str): + if line.startswith(rs): + yield line[len(rs):] + else: + for rule in rules[idx]: + yield from yield_rule(line, rule, depth) sum = 0 for line in lines: - line = '11: 42 31 | 42 11 31' if line.startswith('11: ') else line + line = '11: 42 31 | 42 11 31' if line.startswith('11:') else line line = '8: 42 | 42 8' if line.startswith('8:') else line if ":" in line: idx, r = line.split(": ")