Compare commits

..

14 commits

Author SHA1 Message Date
335db26ad4 wip 2025-12-09 19:34:15 +01:00
cea6397499 wip 2025-12-09 19:27:43 +01:00
f971917640 Solve 2025 day 9 pt 1
Pt 2 is almost there. Need a better flood fill
algorithm.
2025-12-09 14:49:19 +01:00
267ecaebc1 better visualzier 2025-12-09 14:48:57 +01:00
8fbd267d99 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-08 07:56:36 +01:00
ee8d11f84d 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-07 14:57:28 +01:00
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
2 changed files with 49 additions and 38 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 + 1
W = r + 1
osr = 0 #t
osc = 0 #l
H = b - t + 1
W = r - l + 1
osr = t
osc = l
C, Z = mask
def _m(r, c):
return M[r][c] if M else Z

View file

@ -1,28 +1,19 @@
from math import inf
from itertools import combinations
import PIL
from output import ints
from output import svg, D, ints, vdbg
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()
W = set()
B = 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]
@ -37,41 +28,61 @@ 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):
W.add((r, c))
B.add((r, c))
if E == A[0]:
break
S = E
V = V | W
# 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))
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 _within(W, a, b, T, R, B, L):
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
):
p2 = max(p2, max(p2, x * y))
return p1, p2
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__":
inp = """
7,1
11,1
11,7
9,7
9,5
2,5
2,3
7,3 """.strip()
with open("./input/09.txt", "r") as f:
inp = f.read().strip()