From 7e219104ecbe4b4e0fe5261b54decceb38d1d8fa Mon Sep 17 00:00:00 2001 From: Sebastian Seedorf Date: Sat, 19 Dec 2020 13:07:01 +0100 Subject: [PATCH] Day 19 (cleanup) --- day19/part1.py | 1 - day19/part2.py | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) 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(": ")