chiark / gitweb /
24a done
authorBen Harris <bjh21@bjh21.me.uk>
Fri, 14 Jun 2024 20:12:08 +0000 (21:12 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Fri, 14 Jun 2024 20:12:08 +0000 (21:12 +0100)
24/24a.bqn [new file with mode: 0644]

diff --git a/24/24a.bqn b/24/24a.bqn
new file mode 100644 (file)
index 0000000..e17f53b
--- /dev/null
@@ -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