aoc-2024/3/1.py
2024-12-03 00:39:30 -08:00

14 lines
367 B
Python

import re
def get_muls(raw: str) -> list[int]:
finds: list[str] = re.findall(r'mul\([0-9]+,[0-9]+\)', raw)
pairs = []
for f in finds:
parts = f.strip('mul()').split(',')
pairs.append((int(parts[0]), int(parts[1])))
return pairs
with open('data.input') as file:
print(sum(m[0] * m[1] for m in get_muls(file.read())))