Advent of Code 2025 Tribute: de winnaars!
Als Advent of Code sponsor hebben we dit jaar weer onze eigen puzzel gemaakt. We werpen hier een blik op de beste inzendingen.
De opdracht
Naast de officiële Advent of Code puzzels hebben we ook weer onze eigen puzzel gemaakt. Het doel van de puzzel is simpel: door de bomen het bos zien. De kerstman heeft hout nodig, en om bomen te laten groeien heeft de kerstman bedacht om spotlights op het bos te zetten.
Dat de bomen vervolgens op hexagonale vlakken geplant zijn is voor de kerstman niet zo’n punt, maar maakt het voor jou wel wat lastiger.
Als dit jou makkelijk klinkt, dan is de puzzel hier nog steeds te vinden.
De winnaars
De eerste prijs dit jaar gaat naar paiv, die een inzending in Julia heeft opgestuurd:
function evolve!(light, grid, lm, N=1; t0=0)
hs = zeros(Int, size(grid))
xx = [Pos.(1, axes(grid,2)); Pos.(size(grid,1), axes(grid,2))]
res = 0
light(grid, t0+1, lm, hs)
for t in 1:N
cs = counter(q for (i,x) in pairs(grid) if x >= 2
for q in i .+ neibs if get(grid, q, 0) < 0 && q ∉ xx)
us = findall(>=(2), cs)
ix = findall(>=(0), grid)
grid[ix] += lm[ix]
grid[us] += lm[us]
jx = findall(>=(5), grid)
res += length(jx)
grid[jx] .= -1
light(grid, t0+t+1, lm, hs)
end
return res
end
En om dit te visualizeren zit er ook een mooie animatie bij:
Daarnaast sprongen 2 andere inzendingen er ook uit, zoals de recursieve Haskell oplossing van Arno Jacobs:
-- The function with the conditions for the indirect light
fluorescentionRay :: Grid -> Coordinate -> Coordinate -> Coordinate -> Int -> Int -> Coordinates
fluorescentionRay grid (x,y) (dx,dy) (maxX,maxY) cBottom mTreeHeight
| cx > maxX || cy < 0 || cy > maxY = [] -- a range check
| isTree e && th >= mTreeHeight = [(cx,cy)] -- a big tree in the path of the indirect light
| (isEmpty e && cBottom == 0) -- light a the bottom over empty space or seeds
|| (isTree e && cBottom == 0 && th == 0) = [(cx,cy)] ++ fluorescentionRay grid (cx,cy) (dx,dy) (maxX,maxY) cBottom mTreeHeight
| isTree e && th > cBottom -- light over the top of a tree
&& th < mTreeHeight = [(cx,cy)] ++ fluorescentionRay grid (cx,cy) (dx,dy) (maxX,maxY) th mTreeHeight
-- all other conditions
| otherwise = fluorescentionRay grid (cx,cy) (dx,dy) (maxX,maxY) cBottom mTreeHeight
where
(cx,cy) = (x+dx,y+dy)
cxyl = [(cx,cy)]
e = grid !! cy !! cx
(Tree th) = e
en Sem Visscher met een Python one-liner:
''''python3 solution.py < input.txt'''and print(sum(c for y in range(256)if(True if'g'in globals()else(g:=[[[*x]for x in __import__("re").findall(r"\d?[ x]+", l)]for l in list(open(0))[1:-1]]))and(ds:=[(2,0),(0,-1),(-2,0),(0,1),(1,1),(1,0),(-1,1),(-1,0)])and(d:=ds[y%4])and(dl:=[[4,5],[7,5],[7,6],[4,6]])and(g:=[[[g[i][j],[g[i][j][0],'x']][any(g[a][b][0]>=g[i][j][0].replace(' ','0')for e in range(1,max(len(g),len(g[0])))if 0<=(a:=i-e*d[0])<len(g)and 0<=(b:=j-e*d[1])<len(g[0])and g[a][b][0]not in'0 ')]for j in range(len(g[i]))]for i in range(len(g))])and(g:=[[[g[i][j],[g[i][j][0],'@']][any(any(g[a][b][0]not in'0 'and g[a][b][1]==' 'and(h:=max(['-1',*[g[r][t][0]for f in range(1,max(len(g),len(g[0])))if 0<=(r:=i-f*ds[d][0])<len(g)and 0<=(t:=j-f*ds[d][1]+((f+i%2)//2))<len(g[0])and f<e and g[r][t][0]not in'0 ']]))< g[i][j][0].replace(' ','0')and h<g[a][b][0].replace(' ','0')for e in range(1,max(len(g),len(g[0])))if 0<=(a:=i-e*ds[d][0])<len(g)and 0<=(b:=j-e*ds[d][1]+((e+i%2)//2))<len(g[0])and g[a][b][0]not in'0 ')and g[i][j][1]=='x'for d in dl[y%4])]for j in range(len(g[i]))]for i in range(len(g))])and (g:=[[[g[i][j],['-1',g[i][j][1]]][sum(int('2'<=g[a][b][0].replace(' ','0'))for e in range(8)if e not in[1,3]and 0<=(a:=i+ds[e][0])<len(g)and 0<=(b:=j+ds[e][1]-([0,1][e>3 and i%2==0]))<len(g[0]))>=2 and g[i][j][1]in' @'and g[i][j][0]==' ']for j in range(len(g[i]))]for i in range(len(g))])and(g:=[[[str(int(g[i][j][0]if g[i][j][0]!=' 'else'0')+1),g[i][j][1]]if g[i][j][1]in' @'and g[i][j][0]!=' 'else g[i][j]for j in range(len(g[i]))]for i in range(len(g))])and(gc:=(sum(1 if g[i][j][0]!=' 'and g[i][j][0]=='5'else 0 for i in range(len(g))for j in range(len(g[i]))),[[[' 'if g[i][j][0]=='5'else g[i][j][0],' ']for j in range(len(g[i]))]for i in range(len(g))]))and(g:=gc[1])and(c:=gc[0])))
Als honorable mention hebben we dit keer Jan Verbeek (de winnaar van vorig jaar) met handgeschreven WebAssembly:
(func $fluoresce (param $direction i32) (result)
(local $beamtop i32)
(local $beambot i32)
(local $curval i32)
(local $oldpos i32)
(local.set $oldpos (global.get $pos))
(local.set $beamtop (call $gethex))
(local.set $beambot (i32.const 1))
(block $break (loop $loop
(global.set $pos (call_indirect (type $dirfunc) (local.get $direction)))
(br_if $break (i32.eqz (call $inbounds)))
(local.set $curval (call $gethex))
(if (i32.eq (local.get $beambot) (i32.const 1)) (then
(call $hexlight)))
(if (i32.le_s (local.get $beambot) (local.get $curval)) (then
(call $hexlight)
(local.set $beambot (i32.add (local.get $curval) (i32.const 1)))))
(br_if $break (i32.gt_s (local.get $beambot) (local.get $beamtop)))
(br $loop)))
(global.set $pos (local.get $oldpos)))
Tot slot
Helaas konden we niet alle 17 inzendingen laten zien, maar we hebben weer erg genoten van alle leuke inzendingen. Tot volgend jaar!