Skip to content

Commit 818ae62

Browse files
committed
day 03
1 parent 5e0791f commit 818ae62

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

day03.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import re
2+
regex_mul = re.compile(r"mul\(([0-9]+),([0-9]+)\)")
3+
input = open("inputs/day03.txt").read()
4+
print(f"part 1 = {sum(int(match[0]) * int(match[1]) for match in regex_mul.findall(input))}")
5+
6+
regex_op = re.compile(r"(mul|do|don't)\((([0-9]+),([0-9]+))?\)")
7+
enabled = True
8+
result = 0
9+
for op, _, a, b in regex_op.findall(input):
10+
if op == "do":
11+
enabled = True
12+
elif op == "don't":
13+
enabled = False
14+
else:
15+
assert op == "mul"
16+
if enabled:
17+
result += int(a) * int(b)
18+
print(f"part 2 = {result}")

0 commit comments

Comments
 (0)