Skip to content

Commit 59e58d7

Browse files
committed
Add solution to 2024-12-03
1 parent f625b9b commit 59e58d7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

2024/day03/solutions.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import re
2+
3+
with open("input") as f:
4+
data = f.read()
5+
6+
7+
def solve(part1):
8+
res = 0
9+
do = True
10+
for i, j, k in re.findall("(mul\((\d+),(\d+)\)|do\(\)|don't\(\))", data):
11+
if i == "don't()":
12+
do = False
13+
elif i == "do()":
14+
do = True
15+
else:
16+
if do or part1:
17+
res += int(j) * int(k)
18+
return res
19+
20+
21+
# Part 1
22+
print(solve(True))
23+
24+
# Part 2
25+
print(solve(False))

0 commit comments

Comments
 (0)