chiark / gitweb /
12b done
authorBen Harris <bjh21@bjh21.me.uk>
Sun, 12 May 2024 10:19:46 +0000 (11:19 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Sun, 12 May 2024 10:19:46 +0000 (11:19 +0100)
12/12b.bqn [new file with mode: 0644]

diff --git a/12/12b.bqn b/12/12b.bqn
new file mode 100644 (file)
index 0000000..177d917
--- /dev/null
@@ -0,0 +1,28 @@
+# From https://mlochbaum.github.io/BQN/doc/control.html
+While   ← {𝕩•_while_𝕨@}´
+
+Prep←{
+  start⇐'S'=𝕩
+  end⇐'E'=𝕩
+  map⇐'~'-˜𝕩+(start×'a'-'S')+(end×'z'-'E')
+  start∨↩'a'=𝕩
+}
+
+Main←{𝕊⟨start,end,map⟩:
+  can_go_n←1≥(»map)-map
+  can_go_s←1≥(«map)-map
+  can_go_w←1≥(»˘map)-map
+  can_go_e←1≥(«˘map)-map
+  Flow←{
+    𝕩∨(«𝕩∧can_go_n)∨(»𝕩∧can_go_s)∨(«˘𝕩∧can_go_w)∨(»˘𝕩∧can_go_e)
+  }
+  now←start
+  count←0
+  While {𝕤,¬∨´⥊(now∧end)}‿{𝕤
+    now↩Flow now
+    count+↩1
+  }
+  count
+}
+
+•Show Main Prep >•file.Lines ⊑•args