Compare commits

..

6 commits

Author SHA1 Message Date
ca6047c747 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-04 18:59:46 +01:00
cf3a9298d3 Fix aoc lib bug
Lost 1h in 2025 day 4 pt 1 for this. :D

Apparently, ADJ is not used that often.
2025-12-04 18:59:46 +01:00
57ada9e80f 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-04 18:59:46 +01:00
6fd5f20d34 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-04 18:59:46 +01:00
b87c6ed284 Solve 2025 day 1 pt 1-2
Brute force, since I was to newly awake to figure out
the smart solution.
2025-12-04 18:59:46 +01:00
d08fab4101 Initiate Advent of Code 2025 2025-12-04 18:59:46 +01:00
3 changed files with 43 additions and 4 deletions

View file

@ -114,5 +114,5 @@ for i in [str(n).zfill(2) for n in range(1, 26)]:
pass
if not day_no:
print(f"\nStars: {stars}")
print("".join("*" if n < stars else "" for n in range(50)))
print("".join("*" if n < stars else "" for n in range(24)))
print("")

View file

@ -34,7 +34,7 @@ DDa = {
ADJ = [
(-1, -1),
(-1, 0),
(1, -1),
(-1, 1),
(0, -1),
(0, 1),
(1, 1),
@ -60,6 +60,12 @@ def mhd(a, b):
return abs(ar - br) + abs(ac - bc)
def grid(d, o="#"):
"""Transform a string into an iterable matrix. Returns the matrix, row count and col count"""
m = [tuple(r) for r in d.split()]
return set([(r, c) for c in range(len(m[0])) for r in range(len(m)) if m[r][c] == o])
def matrix(d):
"""Transform a string into an iterable matrix. Returns the matrix, row count and col count"""
m = [tuple(r) for r in d.split()]
@ -72,10 +78,12 @@ def mdbg(m):
print("".join(r))
def vdbg(seen, h, w):
def vdbg(seen, h, w, C="#", M=None):
"""Print-debug visited positions of a matrix"""
def _m(r, c):
return M[r][c] if M else "."
for r in range(h):
print("".join(["#" if (r, c) in seen else " " for c in range(w)]))
print("".join([C if (r, c) in seen else _m(r, c) for c in range(w)]))
def vvdbg(seen, h, w):

View file

@ -0,0 +1,31 @@
from output import grid, ADJ
def solve(data):
p1 = 0
p2 = set()
G = grid(data, o="@")
while True:
for r, c in G:
if sum((r + dy, c + dx) in G for dy, dx in ADJ) < 4:
p2.add((r, c))
if p1 == 0:
p1 = len(p2)
if not G & p2:
break
G = G - p2
p2 = len(p2)
return p1, p2
if __name__ == "__main__":
with open("./input/04.txt", "r") as f:
inp = f.read().strip()
p1, p2 = solve(inp)
print(p1)
print(p2)
assert p1 == 1493
assert p2 == 9194