From 90feb14cd5c9d897db8b274c6c6218e3533b365a Mon Sep 17 00:00:00 2001 From: Starnakin Date: Tue, 3 Dec 2024 09:09:43 +0100 Subject: [PATCH] add: 2024/day03/part2 --- 2024/day03/part2.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 2024/day03/part2.py diff --git a/2024/day03/part2.py b/2024/day03/part2.py new file mode 100644 index 0000000..c3cbf63 --- /dev/null +++ b/2024/day03/part2.py @@ -0,0 +1,19 @@ +import re + +text: str + +with open("input.txt") as f: + text = f.read() + +total: int = 0 + +do_or_not: bool = True + +for x, y, don_t, do in re.findall("mul\(([0-9]{0,3})\,([0-9]{0,3})\)|(don\'t)|(do)", text): + if (do != ""): + do_or_not = True + elif (don_t != ""): + do_or_not = False + elif (do_or_not): + total += int(x) * int(y) +print(total) \ No newline at end of file