advent-of-code/2022/day12/day12.bqn
2024-11-12 21:46:18 +01:00

33 lines
1 KiB
BQN
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

map>•FLines•args
IndexOf{<˘>(𝕨)(÷˜|)/𝕨=𝕩}
se¨mapIndexOf¨"SE"
h-'a'¨'z'(e)'a'(s)map
_fixedpoint{𝔽𝔽_𝕣𝔽𝕩}
Dijkstra{h𝕊s:
vis(h)0
dist0(s)(h)
Neighbors{𝕊n:
nsn+¨(-)¨()01
ns ((´¨(vis)>¨)/) # inside the grid
ns ((´¨0¨)/) # inside the grid
ns({¬𝕩vis}¨ns)/ns # unvisited
(1({𝕩h}¨ns)-nh)/ns # reachable height
}
Visit{
´𝕩 ? 𝕩;
nexts((dist)(¬𝕩)) IndexOf 1
nexts({𝕩dist}¨nexts)nexts
nnexts
{dist (1+ndist)(𝕩)}¨Neighbors n # update distances
¬(n)𝕩 # mark node as visited
}
Visit _fixedpoint vis
dist
}
•Show eh Dijkstra s
ssmap IndexOf'a'
•Show ´ss(-h)Dijkstra e