AOC/2024/day03/part2.py

19 lines
373 B
Python
Raw Permalink Normal View History

2024-12-03 03:09:43 -05:00
import re
text: str
with open("input.txt") as f:
text = f.read()
total: int = 0
do_or_not: bool = True
2024-12-03 04:15:53 -05:00
for x, y, don_t, do in re.findall("mul\(([0-9]{1,3})\,([0-9]{1,3})\)|(don\'t\(\))|(do\(\))", text):
2024-12-03 03:09:43 -05:00
if (do != ""):
do_or_not = True
elif (don_t != ""):
do_or_not = False
elif (do_or_not):
total += int(x) * int(y)
print(total)