|
|
@ -2,12 +2,24 @@ import re |
|
|
|
|
|
|
|
|
|
|
|
lines = [l for l in open("input.txt", 'r').read().splitlines()] |
|
|
|
lines = [l for l in open("input.txt", 'r').read().splitlines()] |
|
|
|
|
|
|
|
|
|
|
|
summa, x = 0, [] |
|
|
|
summa, summa2, do = 0, 0, True |
|
|
|
|
|
|
|
|
|
|
|
for l in lines: |
|
|
|
for l in lines: |
|
|
|
x = [i.span() for i in re.finditer("mul\([0-9]{1,3},[0-9]{1,3}\)", l)] |
|
|
|
x = [i.span() for i in re.finditer(r"mul\([0-9]{1,3},[0-9]{1,3}\)", l)] |
|
|
|
|
|
|
|
x2 = [i.span() for i in re.finditer(r"mul\([0-9]{1,3},[0-9]{1,3}\)|do\(\)|don't\(\)", l)] |
|
|
|
|
|
|
|
|
|
|
|
for start, end in x: |
|
|
|
for start, end in x: |
|
|
|
tup = l[start:end].split(',') |
|
|
|
tup = l[start:end].split(',') |
|
|
|
summa += int(tup[0][4:]) * int(tup[1][:-1]) |
|
|
|
summa += int(tup[0][4:]) * int(tup[1][:-1]) |
|
|
|
|
|
|
|
|
|
|
|
print(summa) |
|
|
|
for start,end in x2: |
|
|
|
|
|
|
|
if l[start:end] == 'do()': |
|
|
|
|
|
|
|
do = True |
|
|
|
|
|
|
|
elif l[start:end] == 'don\'t()': |
|
|
|
|
|
|
|
do = False |
|
|
|
|
|
|
|
elif do: |
|
|
|
|
|
|
|
tup = l[start:end].split(',') |
|
|
|
|
|
|
|
summa2 += int(tup[0][4:]) * int(tup[1][:-1]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(summa) |
|
|
|
|
|
|
|
print(summa2) |