2025-12-06 18:02:41 -06:00

32 lines
633 B
Python

import math
INPUT_FILE = "input.txt"
problems: list[list[int]] = []
with open(INPUT_FILE, 'r') as file:
lines: list[str] = file.readlines()
problems = [ [] for _ in range(len(lines[0].split())) ]
# Prepare all problems
for line in lines[:-1]:
for i, n in enumerate([ int(n.strip()) for n in line.split() ]):
problems[i].append(n)
operations: list[str] = lines[-1].split()
total = 0
for i, problem in enumerate(problems):
operation: str = operations[i]
if operation == '+':
total += sum(problem)
elif operation == '*':
total += math.prod(problem)
print(f'Total Value: {total}')