c9a44bfe15
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>
16 lines
588 B
BQN
16 lines
588 B
BQN
⟨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
|