summaryrefslogtreecommitdiff
path: root/2024/3A.py
blob: 2c7d24994c94999e16674ef6a2d6bfcfcdf600a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import re

with open('3.txt', 'r') as f:
    data = f.read()

mul = r'mul\(\d+,\d+\)'
matches = re.findall(mul, data)  

lmuls = []
lmuls.extend(matches)

ints = [l.split("mul(")[1].rstrip(')') for l in lmuls]
print(ints)

muls = 0

for i in ints:
    n1, n2 = map(int, i.split(','))
    print(n1, n2)
    muls += n1 * n2
print(muls)