From cb9cc445c0ce044b81d79eb9f3d92f92f952abd9 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Tue, 3 Dec 2024 21:24:00 -0500 Subject: [PATCH] day3 part2 --- 2024/python/day03.py | 18 ++++++++++++++++-- 2024/samples/day03.txt.part2 | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 2024/samples/day03.txt.part2 diff --git a/2024/python/day03.py b/2024/python/day03.py index 4dff811..4f5e50c 100644 --- a/2024/python/day03.py +++ b/2024/python/day03.py @@ -7,7 +7,6 @@ def part1(rows): total = 0 r = re.compile(r'mul\(\d+,\d+\)') for row in rows: - print(row) muls = r.findall(row) for m in muls: x, y = scanf("mul(%d,%d)", m) @@ -18,7 +17,22 @@ def part1(rows): # @shared.profile def part2(rows): - pass + total = 0 + r = re.compile(r'(mul\(\d+,\d+\)|do\(\)|don\'t\(\))') + enabled = True + for row in rows: + muls = r.findall(row) + for m in muls: + if m == "don't()": + enabled = False + continue + if m == "do()": + enabled = True + continue + if enabled: + x, y = scanf("mul(%d,%d)", m) + total += x * y + print(total) def main(): diff --git a/2024/samples/day03.txt.part2 b/2024/samples/day03.txt.part2 new file mode 100644 index 0000000..30032cb --- /dev/null +++ b/2024/samples/day03.txt.part2 @@ -0,0 +1 @@ +xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))