25 lines
569 B
Python
25 lines
569 B
Python
|
|
import re
|
||
|
|
input = open("input", 'r').read().strip()
|
||
|
|
|
||
|
|
# d = [line for line in input]
|
||
|
|
# d = [[val for val in line.strip()] for line in input]
|
||
|
|
|
||
|
|
def run(part2 = False):
|
||
|
|
sm = 0
|
||
|
|
x = re.findall(r"(mul\(\d*,\d*\))|(do\(\))|(don't\(\))", input)
|
||
|
|
enable = True
|
||
|
|
for item in x:
|
||
|
|
if enable and item[0]:
|
||
|
|
a, b = item[0].split(",")
|
||
|
|
a = int(a[4:])
|
||
|
|
b = int(b[:-1])
|
||
|
|
sm += a * b
|
||
|
|
elif item[1]:
|
||
|
|
enable = True
|
||
|
|
elif part2:
|
||
|
|
enable = False
|
||
|
|
return sm
|
||
|
|
|
||
|
|
print(run())
|
||
|
|
print(run(True))
|