about summary refs log tree commit diff
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2022-12-15T00·32+0100
committerclbot <clbot@tvl.fyi>2022-12-20T19·01+0000
commitc9a44bfe1575691eaec449f2e6d0424de0dbcb8a (patch)
treee14d32cc1a5bd1abd416bbcc5872dd5eaa076ac3
parent15e98314cc1b8a35de70dbb1cfdb81d3ef7e7e9a (diff)
feat(sterni/aoc/2022): day12 BQN solution r/5429
Change-Id: Ib80fe824341964f46a45599c18fa00635ba02aaf
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7600
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Autosubmit: sterni <sternenseemann@systemli.org>
-rw-r--r--users/sterni/exercises/aoc/2022/12/12.bqn16
1 files changed, 16 insertions, 0 deletions
diff --git a/users/sterni/exercises/aoc/2022/12/12.bqn b/users/sterni/exercises/aoc/2022/12/12.bqn
new file mode 100644
index 000000000000..cf42f6f899ca
--- /dev/null
+++ b/users/sterni/exercises/aoc/2022/12/12.bqn
@@ -0,0 +1,16 @@
+⟨ImportBqnLibs,_fix⟩ ← •Import "../../lib.bqn"
+⟨ReplaceAll⟩ ← ImportBqnLibs "strings.bqn"
+i ← >•FLines "input"
+
+elevation ← 'a'-˜⟨"S","E"⟩‿⟨"a","z"⟩ ReplaceAll⌾⥊ i
+starts ← (⊏⟜∞‿0)¨⟨'S'=i,0=elevation⟩
+end ← 'E'=i
+
+Step ← {
+  𝕊 steps:
+  Go ← {𝕏⁼((⊢∾¨↕∘≢)(≤⟜(∞⊸»˘∘+⟜1))˜𝕏elevation)⊑>((⥊⟜∞)∘≢⊸⋈)˜∞⊸»˘1+𝕏steps}
+  steps⌊´Go¨⟨⊢,⌽˘,⍉,⍉⌽⟩
+}
+Shortest ← {⊑end/⊸⊏○⥊Step _fix 𝕩}
+
+•Out¨ "day12.1: "‿"day12.2: "∾¨ •Fmt∘Shortest¨ starts