chiark / gitweb /
12: factorise contruction of can_go_x arrays somewhat
authorBen Harris <bjh21@bjh21.me.uk>
Sun, 12 May 2024 10:57:52 +0000 (11:57 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Sun, 12 May 2024 10:57:52 +0000 (11:57 +0100)
12/12a.bqn
12/12b.bqn

index f0ebe2892a52d6c3e98ee89ab4c7e31ba6a35738..69790d158e678b238b8c335b4687a8ef74d3cbae 100644 (file)
@@ -5,12 +5,10 @@ Prep←{
 }
 
 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)
+  shifts←⟨«,«˘,»˘,»⟩
+  can_go←{1≥(𝕏map)-map}¨shifts
+  Flow←{𝕊now:
+    now∨´can_go{𝕏now∧𝕨}¨⌽shifts
   }
   count←0
   {count+↩1 ⋄ Flow 𝕩} •_while_ {¬∨´⥊(𝕩∧end)} start
index d92f7c9c62b01d1b83c9d8f7a61330866e35759e..66163c35f3c312033ca5e679ec2a0436844b7b8f 100644 (file)
@@ -6,12 +6,10 @@ Prep←{
 }
 
 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)
+  shifts←⟨«,«˘,»˘,»⟩
+  can_go←{1≥(𝕏map)-map}¨shifts
+  Flow←{𝕊now:
+    now∨´can_go{𝕏now∧𝕨}¨⌽shifts
   }
   count←0
   {count+↩1 ⋄ Flow 𝕩} •_while_ {¬∨´⥊(𝕩∧end)} start