-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday3.py
More file actions
executable file
·37 lines (25 loc) · 740 Bytes
/
day3.py
File metadata and controls
executable file
·37 lines (25 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import re
from aoc_utils import * # type: ignore
from aocd import get_data
data = get_data(year=2024, day=3, block=True)
def part_one(data):
instructions = re.findall(r"mul\((\d+),(\d+)\)", data)
total = 0
for a, b in instructions:
total += int(a) * int(b)
return total
def part_two(data):
instructions = re.findall(r"mul\(\d+,\d+\)|do\(\)|don't\(\)", data)
enable = True
total = 0
for instruction in instructions:
if instruction == "do()":
enable = True
elif instruction == "don't()":
enable = False
elif enable:
a, b = ints(instruction)
total += a * b
return total
print(part_one(data))
print(part_two(data))