From c37f6ef2639d0627a44b76b9d64612aa7c410b5d Mon Sep 17 00:00:00 2001 From: kwout Date: Thu, 5 Dec 2024 12:23:14 -0500 Subject: [PATCH] 2024 day 3 part 1 solved --- 2024/3.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 2024/3.py diff --git a/2024/3.py b/2024/3.py new file mode 100644 index 0000000..6abb925 --- /dev/null +++ b/2024/3.py @@ -0,0 +1,13 @@ +import re + +lines = [l for l in open("input.txt", 'r').read().splitlines()] + +summa, x = 0, [] + +for l in lines: + x = [i.span() for i in re.finditer("mul\([0-9]{1,3},[0-9]{1,3}\)", l)] + for start, end in x: + tup = l[start:end].split(',') + summa += int(tup[0][4:]) * int(tup[1][:-1]) + +print(summa) \ No newline at end of file