Compare commits

..

4 commits

Author SHA1 Message Date
bebfa59762 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-03 07:30:04 +01:00
8bf07308ff 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-02 18:55:50 +01:00
383dfa9e7a Solve 2025 day 1 pt 1-2
Brute force, since I was to newly awake to figure out
the smart solution.
2025-12-01 08:04:10 +01:00
5cc189cde0 Initiate Advent of Code 2025 2025-11-30 19:25:39 +01:00
3 changed files with 4 additions and 43 deletions

View file

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

View file

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

View file

@ -1,31 +0,0 @@
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