Added 2024 and day 1-3 solves in python

This commit is contained in:
d4rkr41n
2024-12-03 16:18:24 -06:00
parent f00e52f8a5
commit 2d5ce9ade1
12 changed files with 2441 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
import re
with open("../input.txt", "r") as fp:
inputs = [line.rstrip() for line in fp]
def mul(a,b):
return a*b
mul_reg = re.compile(r"mul\([0-9]{1,3},[0-9]{1,3}\)|do\(\)|don\'t\(\)")
sum = 0
do = True
for line in inputs:
result = re.findall(mul_reg, line)
for group in result:
if "don't" in group:
do = False
elif "do" in group:
do = True
elif "mul" in group and do:
sum += eval(group)
print(sum)