Compare commits

..

8 commits

Author SHA1 Message Date
05c7b5bfb9 Solve 2025 day 6 pt 1-2
Lost 20 minutes in pt 1 not rembering that a print()
of a zip consumes it and makes it not loopable: had
I just used list(zip()) or removed the print, I would
have had the answer in a decent time frame.

Pt 2 was fun! I first experienced with ljust() and
rjust(), only to realize the input was mixed. Instead,
I threated the input as a grid.
2025-12-06 07:55:40 +01:00
11168d283e Solve 2025 day 5 pt 1-2
Part 2 was too hard for me, since I initially worked
with range(s, e). It quickly became out of hand.

A funnel method was instead used.
2025-12-05 08:29:06 +01:00
6600f416d2 Solve 2025 day 4 pt 1-2
Had a bug in my aoc lib, that lost me an hour for pt 1:
The ADJ dict has SW twice, and lacks NE.

The bug is at least 2 years old. It was introduced in 661f18dca4
and apparently has never worked. I guess it has not been used
up until now.

That being said, it was straight-forward. A new helper for
grid was used the first time, as well as an improved vdbg()
function.
2025-12-05 08:29:06 +01:00
d1a1ce775e Fix aoc lib bug
Lost 1h in 2025 day 4 pt 1 for this. :D

Apparently, ADJ is not used that often.
2025-12-05 08:29:06 +01:00
8a1910e174 Solve 2025 day 3 pt 1-2
For the first part, I used itertools.combinations
to find the highest pairs of batteries. And as
expected, that solution did not scale well for pt 2.

I figured out that reducing batteries until the top
most 12 (and 2) remained was the correct way to go.

the _maxj(line, C) function is the hive conclusion
from the solution mega thread. I really liked this
brilliant use of a while loop to exlude batteries.

 - The first char just skip the while loop. A char
   emptying the battery list also does this.
2025-12-05 08:29:06 +01:00
4cbd10fe4d Solve 2025 day 2 pt 1-2
I tried to solve it without regexp at first, failed
brutally. Cut the line count by 80% using a regexp
instead.

It was also funny to get all square roots.
2025-12-05 08:29:06 +01:00
04bb4c93ac Solve 2025 day 1 pt 1-2
Brute force, since I was to newly awake to figure out
the smart solution.
2025-12-05 08:29:06 +01:00
19c4a2626f Initiate Advent of Code 2025 2025-12-05 08:29:06 +01:00
3 changed files with 72 additions and 1 deletions

View file

@ -0,0 +1,31 @@
from output import ints
def solve(data):
p1 = None
p2 = 0
ranges, ids = data.split("\n\n")
ids = ints(ids)
R = [ints(line) for line in ranges.split()]
p1 = sum(any(s <= n <= e for s, e in R) for n in ids)
c = 0
for s, e in sorted(R):
s = max(c + 1, s)
if s <= e:
p2 += e - s + 1
c = max(e, c)
return p1, p2
if __name__ == "__main__":
with open("./input/05.txt", "r") as f:
inp = f.read().strip()
p1, p2 = solve(inp)
print(p1)
print(p2)
assert p1 == 509
assert p2 == 336790092076620

View file

@ -0,0 +1,40 @@
import re
from math import prod
def solve(data):
p1 = 0
p2 = 0
rows = data.splitlines()
J = max(len(r) for r in rows) + 1
rows = [r.ljust(J) for r in rows]
ops = rows.pop()
s = 0
for ows in re.findall(r"(\S\s+)", ops):
o, *ws = ows
e = s + len(ws)
col = [ns for ns in [r[s:e] for r in rows]]
s += len(ows)
col1 = [int(r) for r in col]
col2 = [int("".join([nsc for nsc in ns if nsc.isdigit()])) for ns in zip(*col)]
match o:
case "*":
p1 += prod(col1)
p2 += prod(col2)
case "+":
p1 += sum(col1)
p2 += sum(col2)
return p1, p2
if __name__ == "__main__":
with open("./input/06.txt", "r") as f:
inp = f.read().strip()
p1, p2 = solve(inp)
print(p1)
print(p2)
assert p1 == 5524274308182
assert p2 == 8843673199391

View file

@ -8,7 +8,7 @@ RUN pip install waitress==3.0.2
FROM reqs AS app
RUN mkdir /app/templates
COPY *.jinja2 /app/templates
COPY templates/*.jinja2 /app/templates
COPY app.py app.py
ENV AOC_TOKEN=