Added 2024 and day 1-3 solves in python
This commit is contained in:
@@ -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)
|
||||
Reference in New Issue
Block a user