Tree processing in Array languages

https://asherbhs.github.io/apl-site/trees/intro.html

(not the usual linked nodes)

#apl #apljk #arrayprogramming #cs #plt

Introduction — Doing Things in Dyalog APL

init:1+!n:#:d:`I$","\'0:"08.in"
ds:1_'ds@<ds:{(+/t*t:d[x]-d[y]),x,y}.'p@&</'p:+!n,n
conn:{(x*~f)+x[y[0]]*f:x=x[y[1]]}
steps:1000#
:one:*/t 3#>t:.#'=init conn/steps ds
:two:*/*+d {:[&/g=*g:conn[x;*y];*y;o[g;1_y]]}[init;ds]

Part 2 takes a metric eternity to converge. There must be a better solution, but this will have to do for now.

#AdventOfCode #AoC2025 #APLJK #ArrayProgramming

rng:!#*data:0:"07.in"
spls:l@&0<#'l:&'"^"=1_data
msks:(+/rng=/:(-1;1)+)@/:/:spls
f:{spl:+/(n@&0<n)*msks[y]@&0<n:|/+t:(1_x)*/:rng=/:spls[y]
str:(1_x)*~|/t
((+/0<n)+*x),str+spl}
:(one;two):(*:;+/1_)@\:(0,"S"=*data) f/!# spls

It was a pleasant surprise that a single fold could solve both parts.

#AdventOfCode #AoC2025 #ArrayProgramming #APLJK

d:0:"06.in"
op:(+/;*/)@"*"=op@&~" "=op:*|d
:one:+/op@'+.'1_|d
:two:+/op@'n 1_'.=+\~n:0,.'+|1_|d

The fact that the input file was nearly valid K was helpful.

#AdventOfCode #APLJK #AoC2025 #ArrayProgramming

nr:*&~#'d:0:"05.in"
rng@:<rng:`I$"-"\'nr# d
ids:`I$(nr+1)_d
merge:{:[~#:y
,x
x[1]<y[0;0]-1
(,x),o[*y;1_y]
o[x[0],(x[1]|y[0;1])
1_y]]}
:one:+/|/+({~(z<x)|z>y}.'rng)@\:/:ids
:two:+/1+--/'merge[*rng;1_rng]

#AdventOfCode #AoC2025 #APLJK

pad:+z'+(z:0,|0,|:)'
d:pad"@"=0:"04.in"
sh:{y w!x+!w:#:y}
eight:(n w@;n e@;s w@;s e@
e:+s@+:
w:+n@+:
n:sh[1;]
s:sh[-1;])
acc:{x*4>+/eight@\:x}
:one:+//acc d
:two:+//d-{x*~acc x}/d

array problems 🤝 array programming languages

#AdventOfCode #AoC2025 #APLJK

w:#*data:`I$''0:"03.in"
step:{(acc;len;row):x
:[len=# acc
x
(acc,row i
len
row*~(!w)<1+i:*>((# acc)+1+w-len)# row)]}
solve:{+/{`I$,/$*step/(();x;y)}[x;]'data}
:(one;two):solve'2 12

Great fun today.

#AdventOfCode #APLJK

data:0:"01.in"
sign:+/(-1;1)*"LR"=\:data[;0]
count:+/0=100!
:one:count pos:+\50,sign*rot:`I$1_'data
base:1_{y&-1+x}':pos
:two: +/base {count x+1+!y}' rot

This should be executable using https://codeberg.org/ngn/k

#AdventOfCode #APLJK

k

k

Codeberg.org
This is quite a nice intro to the k programming language:
https://github.com/gitonthescene/ngnk-libs/tree/master/tutorial
#apljk #k
ngnk-libs/tutorial at master · gitonthescene/ngnk-libs

Contribute to gitonthescene/ngnk-libs development by creating an account on GitHub.

GitHub
I will be in Toronto in the week of April 15th. I’d love to meet you and chat. Get in touch, let’s grab a lunch. A rough list of interests and potential conversation starters → #SoftwareArchitecture #DataDrivenProgramming #FunctionalProgramming #ProgrammingLanguages #Clojure #Erlang #APLJK #SmallWeb #DarkSouls #Coffee #StayAtHomeDad #Kettlebells #Toronto