advent of code 2025

day 6... :(

kot.pink 144b3b2b 4637a3af

verified
Changed files
+52
+48
6.py
···
+
import sys
+
from operator import mul, add
+
from functools import reduce
+
+
total_wordwise = 0
+
total_digitwise = 0
+
file = '6.input' if len(sys.argv) <= 1 else sys.argv[1]
+
+
columns = []
+
ops = []
+
op_line = None
+
+
for line in open(file).readlines():
+
line = line.strip('\n')
+
for word in line.split(' '):
+
if not word: continue
+
if word in '+*':
+
ops.append(word)
+
op_line = line
+
else:
+
columns.append(word)
+
+
for op_i, op in enumerate(ops):
+
column = [int(c) for i, c in enumerate(columns) if i % len(ops) == op_i]
+
if op == '+':
+
total_wordwise += sum(column)
+
elif op == '*':
+
total_wordwise += reduce(mul, column, 1)
+
+
print(f'p1: {total_wordwise}')
+
+
lines = []
+
op_pos = [i for i, ch in enumerate(op_line) if ch in '+*']
+
for line in open(file).readlines():
+
if line.strip() == op_line.strip(): break
+
words = [line[i:j][:-1] for i, j in zip([0] + op_pos[1:], op_pos[1:] + [None])]
+
lines.append(words)
+
+
for op_i, op in enumerate(ops):
+
cols = [line[i] for i in range(len(lines[0])) if i % len(ops) == op_i for line in lines]
+
digits = [col[i] for i in range(len(cols[0])) for col in cols]
+
numbers = [int(''.join(digits[i:i+len(cols)])) for i in range(0, len(digits), len(cols))]
+
if op == '+':
+
total_digitwise += sum(numbers)
+
elif op == '*':
+
total_digitwise += reduce(mul, numbers, 1)
+
+
print(f'p2: {total_digitwise}')
+4
6.test
···
+
123 328 51 64
+
45 64 387 23
+
6 98 215 314
+
* + * +