Solved 2025 Day 6 Parts 1 & 2
This commit is contained in:
1 parent
d5d846ab0c
commit
75982f2b96
6 files changed
+107
No files matched your search
@@ -0,0 +1,31 @@
|
||||
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}')
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user