24 lines
473 B
Python
24 lines
473 B
Python
|
#!/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=}')
|