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,58 @@
|
||||
import math
|
||||
|
||||
INPUT_FILE = "input.txt"
|
||||
|
||||
problems: list[list[int]] = []
|
||||
|
||||
with open(INPUT_FILE, 'r') as file:
|
||||
lines: list[str] = file.readlines()
|
||||
|
||||
raw: list[str] = []
|
||||
for line in lines[:-1]:
|
||||
raw.append(line[:-1])
|
||||
|
||||
problems = [ [] for _ in range(len(lines[0].split())) ]
|
||||
|
||||
problem_i = len(problems) - 1
|
||||
# Prepare all problems
|
||||
for x in range(len(raw[0])):
|
||||
column_divider = True
|
||||
n = ''
|
||||
for y in range(len(raw)):
|
||||
c = raw[y][x]
|
||||
|
||||
if c != ' ':
|
||||
column_divider = False
|
||||
n += c
|
||||
|
||||
if n:
|
||||
problems[problem_i].append(int(n))
|
||||
|
||||
if column_divider:
|
||||
problem_i -= 1
|
||||
|
||||
|
||||
|
||||
# for line in lines[:-1]:
|
||||
# for c in reversed(line):
|
||||
# for i, n in enumerate([ int(n.strip()) for n in line.split() ]):
|
||||
# problems[i].append(n)
|
||||
|
||||
operations: list[str] = list(reversed(lines[-1].split()))
|
||||
|
||||
total = 0
|
||||
for i, problem in enumerate(problems):
|
||||
operation: str = operations[i]
|
||||
|
||||
if operation == '+':
|
||||
print(f'{problem} {operation} = {sum(problem)}')
|
||||
|
||||
total += sum(problem)
|
||||
elif operation == '*':
|
||||
print(f'{problem} {operation} = {math.prod(problem)}')
|
||||
total += math.prod(problem)
|
||||
|
||||
print(f'Total Value: {total}')
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user