diff --git a/aoc_wim/aoc2024/q03.py b/aoc_wim/aoc2024/q03.py new file mode 100644 index 0000000..5dadfbb --- /dev/null +++ b/aoc_wim/aoc2024/q03.py @@ -0,0 +1,18 @@ +""" +--- Day 3: Mull It Over --- +https://adventofcode.com/2024/day/3 +""" +from aocd import data +import parse + + +pat = "mul({:d},{:d})" +a = sum(x * y for x, y in parse.findall(pat, data)) +print("answer_a:", a) + +while "don't()" in data: + data, tail = data.split("don't()", 1) + if "do()" in tail: + data += tail.split("do()", 1)[1] +b = sum(x * y for x, y in parse.findall(pat, data)) +print("answer_b:", b) diff --git a/tests/2024/03/0.txt b/tests/2024/03/0.txt new file mode 100644 index 0000000..8b81796 --- /dev/null +++ b/tests/2024/03/0.txt @@ -0,0 +1,3 @@ +xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5)) +161 +- diff --git a/tests/2024/03/1.txt b/tests/2024/03/1.txt new file mode 100644 index 0000000..e9518f3 --- /dev/null +++ b/tests/2024/03/1.txt @@ -0,0 +1,3 @@ +xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5)) +- +48