chiark / gitweb /
12: Use the primitive •_while_: it's actually easier to understand
authorBen Harris <bjh21@bjh21.me.uk>
Sun, 12 May 2024 10:41:46 +0000 (11:41 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Sun, 12 May 2024 10:41:46 +0000 (11:41 +0100)
12/12a.bqn
12/12b.bqn

index 12a1975a547a05562f9e3199662eceadb3d13964..f0ebe2892a52d6c3e98ee89ab4c7e31ba6a35738 100644 (file)
@@ -1,6 +1,3 @@
-# From https://mlochbaum.github.io/BQN/doc/control.html
-While   ← {𝕩•_while_𝕨@}´
-
 Prep←{
   start⇐'S'=𝕩
   end⇐'E'=𝕩
@@ -15,12 +12,8 @@ Main←{𝕊⟨start,end,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+↩1 ⋄ Flow 𝕩} •_while_ {¬∨´⥊(𝕩∧end)} start
   count
 }
 
index 177d917a2e5739566c789a00321b9457960af966..d92f7c9c62b01d1b83c9d8f7a61330866e35759e 100644 (file)
@@ -1,6 +1,3 @@
-# From https://mlochbaum.github.io/BQN/doc/control.html
-While   ← {𝕩•_while_𝕨@}´
-
 Prep←{
   start⇐'S'=𝕩
   end⇐'E'=𝕩
@@ -16,12 +13,8 @@ Main←{𝕊⟨start,end,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+↩1 ⋄ Flow 𝕩} •_while_ {¬∨´⥊(𝕩∧end)} start
   count
 }