(update) day 6 part 1, part 2 halfway
This commit is contained in:
32
2025/06/main.py
Normal file
32
2025/06/main.py
Normal 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)
|
||||
Reference in New Issue
Block a user