advent_of_code/2024/3/3.py

24 lines
473 B
Python
Raw Permalink Normal View History

2024-12-04 18:16:14 +01:00
#!/usr/bin/env python
# 2024 - Advent Of Code 3
import re
#file = 'input_example.txt'
file = 'input.txt'
# pylint: disable=consider-using-with
input_lines = [line.strip('\n') for line in open(file, encoding="utf-8")]
re_mul = re.compile(r'mul\((\d+),(\d+)\)')
accum = 0
for l in input_lines:
m = re_mul.findall(l)
if m:
print(m)
m_list = [int(x[0]) * int(x[1]) for x in m]
print(m_list)
accum += sum(m_list)
print(f'{accum=}')