Compare commits

..

12 commits

Author SHA1 Message Date
b8409db06c Solve 2025 day 9 pt 2
Flood fill was too expensive, so I tried solving it with ray casting.

I believe it is the 2nd or 3rd time during 11 runs where it has been
requested.

wip

wip
2025-12-10 00:35:25 +01:00
ae676bf112 Solve 2025 day 9 pt 1
Pt 2 is almost there. Need a better flood fill
algorithm.
2025-12-10 00:34:12 +01:00
34fb92403e Solve 2025 day 8 pt 1-2
For the First time this season, pt 2 was not an epic
HOLY SHIIIT!!! facemelter.

I stared at my code in disbelief during pt 1 for several
minutes before I increased the test point from from 40
to 1000 and got the right answer.
2025-12-10 00:34:12 +01:00
8683885438 Solve 2025 day 7 pt 1-2
For part 1, BFS is used since there is no need to
visit each splitter more than once to count visited
splitters.

For part 2, the code initially removed the visited
check. This failed miserably, losing momentum aound
Y=54-56.

A recursive function with memoization solves it much
faster.
2025-12-10 00:34:12 +01:00
68be80a4d4 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-10 00:34:12 +01:00
2d3caced7f 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-10 00:34:12 +01:00
ac6b97590c 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-10 00:34:12 +01:00
c3c2dd5759 Fix aoc lib bug
Lost 1h in 2025 day 4 pt 1 for this. :D

Apparently, ADJ is not used that often.
2025-12-10 00:34:12 +01:00
4a070e827b 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-10 00:34:12 +01:00
4927b78e59 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-10 00:34:12 +01:00
56ca9d19c4 Solve 2025 day 1 pt 1-2
Brute force, since I was to newly awake to figure out
the smart solution.
2025-12-10 00:34:12 +01:00
f0f78fa25c Initiate Advent of Code 2025 2025-12-10 00:34:12 +01:00
2 changed files with 38 additions and 49 deletions

View file

@ -91,10 +91,10 @@ def vdbg(seen, mask=("#", "."), M=None):
r = max(r, x)
b = max(b, y)
l = min(l, x)
H = b - t + 1
W = r - l + 1
osr = t
osc = l
H = b + 1
W = r + 1
osr = 0 #t
osc = 0 #l
C, Z = mask
def _m(r, c):
return M[r][c] if M else Z

View file

@ -1,19 +1,28 @@
from math import inf
from itertools import combinations
import PIL
from output import svg, D, ints, vdbg
from output import ints
def solve(data):
p1 = 0
p2 = 0
A = [tuple(ints(pos)) for pos in data.splitlines()]
T = inf
R = 0
B = 0
L = inf
for r, c in A:
T = min(r, T)
R = max(c, R)
B = max(r, B)
L = min(c, L)
S = A[0]
V = set()
B = set()
W = set()
while True:
V.add(S)
W.add(S)
y, x = S
he = [(r, c) for r, c in A if r == y and (r, c) not in V]
ve = [(r, c) for r, c in A if c == x and (r, c) not in V]
@ -28,61 +37,41 @@ def solve(data):
y2, x2 = E
for r in range(min(y, y2), max(y, y2) + 1):
for c in range(min(x, x2), max(x, x2) + 1):
B.add((r, c))
W.add((r, c))
if E == A[0]:
break
S = E
# find out a better start for Flood fill by visualizing
Y = 50000
X = 25000
# or, find a way to floodfill without BFS
# end
y, x = Y, X
Q = [(y, x)]
V = V | B
while Q:
yx = Q.pop()
if yx in V:
continue
V.add(yx)
y, x = yx
for dy, dx in D:
Q.append((dy + y, dx + x))
V = V | W
for a, b in combinations(A, r=2):
y1, x1 = a
y2, x2 = b
x = abs(x1 - x2) + 1
y = abs(y1 - y2) + 1
p1 = max(p1, x * y)
if (
len(
set(
[
(min(y1, y2), min(x1, x2)),
(min(y1, y2), max(x1, x2)),
(max(y1, y2), min(x1, x2)),
(max(y1, y2), max(x1, x2)),
]
)
- V
)
== 0
):
if _within(W, a, b, T, R, B, L):
p2 = max(p2, max(p2, x * y))
return p1, p2
if __name__ == "__main__":
inp = """
7,1
11,1
11,7
9,7
9,5
2,5
2,3
7,3 """.strip()
def _within(W, a, b, T, R, B, L):
y1, x1 = a
y2, x2 = b
for r in range(min(y1, y2) + 1, max(y1, y2)):
for c in range(min(x1, x2) + 1, max(x1, x2)):
if (r, c) in W:
continue
for s, e in [(T, r), (r, B)]:
z = sum((nr, c) in W for nr in range(s, e))
if z and z % 2 == 0:
return False
for s, e in [(L, c), (c, R)]:
z = sum((r, nc) in W for nc in range(s, e))
if z and z % 2 == 0:
return False
return True
if __name__ == "__main__":
with open("./input/09.txt", "r") as f:
inp = f.read().strip()