From 82b83c029f8b4f262d421deff04dc1b3ee00d4ce Mon Sep 17 00:00:00 2001 From: Panadestein Date: Tue, 17 Dec 2024 01:00:38 +0100 Subject: [PATCH] feat: learn from dzaima's solution of day 16. --- src/aoc24.org | 20 ++++++++++++++++++++ src/bqn/aoc24.bqn | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/aoc24.org b/src/aoc24.org index cd10d54..97f0801 100644 --- a/src/aoc24.org +++ b/src/aoc24.org @@ -338,6 +338,26 @@ powers of the adjacency matrix. This method is unfortunately slower than simple #+RESULTS: : "Computed 1446158 and 1446175 in 0.0177348094s" +** XVI + +I dislike graph algorithms for their messy, imperative solutions with impurities and fancy data structures. +This problem is usually solved with Dijkstra, but after days of "Fortranized" DFS and BFS, I turned to an +expert array programmer's [[https://github.com/dzaima/aoc][solution]] and reworked mine: + +#+begin_src bqn :tangle ./bqn/aoc24.bqn :exports both + XVI ← { + r‿s‿e ← ⟨'#'⊸≠, 'S'⊸=, 'E'⊸=⟩{𝕎𝕩}¨•FLines Input𝕩 + _fp ← {𝔽∘⊢⍟≢⟜𝔽_𝕣∘⊢⍟≢⟜𝔽𝕩} ⋄ _m ← {𝕩{𝕏𝕨}¨𝔽⟨»,»˘,«,«˘⟩} ⋄ inf ← -2⋆31 + dij ← ⌊´∘{⟨⊢_m, 1⊸⌽⌊1⊸⌽⁼, ⊢⟩{r<⊸×𝕎𝕩}¨⟨𝕩+1, 𝕩+1e3, 𝕩⟩}_fp 0‿inf‿0‿0× diff --git a/src/bqn/aoc24.bqn b/src/bqn/aoc24.bqn index 1f09e4d..c8a5dc6 100644 --- a/src/bqn/aoc24.bqn +++ b/src/bqn/aoc24.bqn @@ -175,3 +175,13 @@ XV ← { w↩wd ⋄ rid DFS´m ⋄ zwei ⇐ +´⥊100‿1×⎉1>/○⥊⟜(↕≢)'['=w } XV _is 15 + +XVI ← { + r‿s‿e ← ⟨'#'⊸≠, 'S'⊸=, 'E'⊸=⟩{𝕎𝕩}¨•FLines Input𝕩 + _fp ← {𝔽∘⊢⍟≢⟜𝔽_𝕣∘⊢⍟≢⟜𝔽𝕩} ⋄ _m ← {𝕩{𝕏𝕨}¨𝔽⟨»,»˘,«,«˘⟩} ⋄ inf ← -2⋆31 + dij ← ⌊´∘{⟨⊢_m, 1⊸⌽⌊1⊸⌽⁼, ⊢⟩{r<⊸×𝕎𝕩}¨⟨𝕩+1, 𝕩+1e3, 𝕩⟩}_fp 0‿inf‿0‿0×