Skip to content

Commit 717e2e3

Browse files
committed
Day 6
1 parent b7d795f commit 717e2e3

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

2025/06.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from os import environ
2+
from functools import reduce
3+
from itertools import groupby
4+
from math import prod
5+
6+
lines = open("06.sample.txt" if environ.get("DEBUG") else "06.txt").read().splitlines()
7+
8+
print(
9+
sum(
10+
reduce(((int.__mul__, int.__add__)[c[-1] == "+"]), map(int, c[:-1]))
11+
for c in zip(*[l.split() for l in lines if l.strip()])
12+
)
13+
)
14+
15+
cols = ["".join(c) for c in zip(*[l.ljust(max(len(x) for x in lines)) for l in lines])]
16+
17+
18+
def do_block(g):
19+
return (sum if any(c.endswith("+") for c in g) else prod)(
20+
int(c[:-1].replace(" ", "")) for c in g if c[:-1].strip()
21+
)
22+
23+
24+
print(
25+
sum(
26+
do_block(list(g))
27+
for k, g in groupby(cols, key=lambda x: not x.strip())
28+
if not k
29+
)
30+
)

0 commit comments

Comments
 (0)