From: Ben Harris Date: Fri, 14 Jun 2024 20:12:08 +0000 (+0100) Subject: 24a done X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=dc2126892c064773f2b17d4fdd32408c27c54e00;p=aoc-2022.git 24a done --- diff --git a/24/24a.bqn b/24/24a.bqn new file mode 100644 index 0000000..e17f53b --- /dev/null +++ b/24/24a.bqn @@ -0,0 +1,38 @@ +# We represent an obstacle as a function from time to a map of +# obstructed squares. BQN supports first-class functions, but the +# syntax is less confusing if they're wrapped in namespaces. + +Blizzards←{𝕊⟨map,fn⟩: + # Blizzards get rotated (by Fn) on a torus that doesn't include the + # walls. + AtTime⇐{ (𝕩⊸Fn) ⌾ ((⟨1,1⟩⊸↓)∘(⟨¯1,¯1⟩⊸↓)) map } +} + +Walls←{𝕊 map: + # Walls are boring and ignore the time. + AtTime⇐{ 𝕩 ⊢ map } +} + +Prep←{ + map←>𝕩 + obstacles⇐⟨ + Walls '#'=map + Blizzards ⟨'^'=map,⌽⟩ + Blizzards ⟨'v'=map,-⊸⌽⟩ + Blizzards ⟨'<'=map,⌽˘⟩ + Blizzards ⟨'>'=map,-⊸⌽˘⟩ + ⟩ + start⇐(('.'⊸=)∧∊)⌾⥊map + end ⇐(('.'⊸=)∧∊)⌾(⌽∘⥊)map +} + + +Main←{𝕊⟨obstacles,start,end⟩: + Flow←{𝕊⟨t,can_be⟩: + (∨´{𝕏can_be}¨⟨«,»,«˘,»˘,⊢⟩) ∧¬(∨´{𝕩.AtTime t}¨obstacles) + } + ⟨t,·⟩ ← {𝕊⟨t,can_be⟩:⟨t+1,Flow⟨t+1,can_be⟩⟩} •_while_ {𝕊⟨·,can_be⟩:¬∨´⥊can_be∧end} ⟨0,start⟩ + t +} + +•Show Main Prep •file.Lines ⊑•args