From 232426c2842597a3168f27db5194339aa602ad1f Mon Sep 17 00:00:00 2001 From: Holly McFarland Date: Wed, 4 Dec 2024 18:51:37 -0500 Subject: [PATCH] day 3 --- day_03/part_a.py | 15 +++++++++++++++ day_03/part_b.py | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 day_03/part_a.py create mode 100644 day_03/part_b.py diff --git a/day_03/part_a.py b/day_03/part_a.py new file mode 100644 index 0000000..1210783 --- /dev/null +++ b/day_03/part_a.py @@ -0,0 +1,15 @@ +import aocd + +import re + +def mul(a, b): + return int(a)*int(b) + +def solve(data): + return sum(mul(*match) for match in re.findall(r'mul\((\d+),(\d+)\)', data)) + +if __name__ == '__main__': + solution = solve(aocd.get_data(year=2024, day=3)) + + print(solution) + aocd.submit(solution, year=2024, day=3, part='a') \ No newline at end of file diff --git a/day_03/part_b.py b/day_03/part_b.py new file mode 100644 index 0000000..8f5b822 --- /dev/null +++ b/day_03/part_b.py @@ -0,0 +1,16 @@ +import aocd + +import re + +def mul(a, b): + return int(a)*int(b) + +def solve(data): + data = ''.join(segment.split("don't()")[0] for segment in data.split('do()')) + return sum(mul(*match) for match in re.findall(r'mul\((\d+),(\d+)\)', data)) + +if __name__ == '__main__': + solution = solve(aocd.get_data(year=2024, day=3)) + + print(solution) + aocd.submit(solution, year=2024, day=3, part='b') \ No newline at end of file