This commit is contained in:
2025-10-19 19:22:00 +03:00
parent 37f1ac7c03
commit 178624f591
3 changed files with 82 additions and 5 deletions
+7 -5
View File
@@ -3,18 +3,20 @@ import re
data = open("input.txt").read().strip()
def mul(a, b):
return a*b
return a * b
print(sum(eval(x) for x in re.findall("mul\(\d{1,3},\d{1,3}\)", data)))
q = "mul\(\d{1,3},\d{1,3}\)|do\(\)|don't\(\)"
print(sum(eval(x) for x in re.findall(r"mul\(\d{1,3},\d{1,3}\)", data)))
q = r"mul\(\d{1,3},\d{1,3}\)|do\(\)|don't\(\)"
f = True
s = 0
for x in re.findall(q, data):
if x=='do()':
if x == "do()":
f = True
elif x=='don\'t()':
elif x == "don't()":
f = False
elif f:
s += eval(x)