(update) day 6 part 1, part 2 halfway

This commit is contained in:
2025-12-21 20:32:10 +01:00
parent cf756f0482
commit 6e48b42abf
3 changed files with 41 additions and 0 deletions

32
2025/06/main.py Normal file
View File

@ -0,0 +1,32 @@
from functools import reduce # Required in Python 3
import operator
def prod(iterable):
return reduce(operator.mul, iterable, 1)
with open("example", "+r") as file:
f = file.readlines()
arr = [x.split() for x in f]
operations = arr[-1]
numbers = 0
for i, op in enumerate(operations):
values = [int(x[i]) for x in arr if x[i].isdigit()]
if op == "+":
numbers += sum(values)
if op == "*":
numbers += prod(values)
print("part1", numbers)
for i, op in enumerate(operations):
values: list = []
for x in arr:
if x[i].isdigit():
length = len(x[i])
values.append(
list(reversed([x[i][z : z + 1] for z in range(0, len(x[i]), 1)]))
)
print(values)