chiark / gitweb /
22b done
authorBen Harris <bjh21@bjh21.me.uk>
Thu, 6 Jun 2024 14:07:52 +0000 (15:07 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Thu, 6 Jun 2024 14:07:52 +0000 (15:07 +0100)
First time it ran to completion, it gave the right answer

22/22b.bqn

index a9dfbfd44b728cce074b3f581e8daea2dd90e8e9..8687d7e051090183b213b7aa0db746a19a21ba04 100644 (file)
@@ -13,7 +13,7 @@ TR←{⟨1,¯1⟩×⌽𝕩}
 Main←{𝕊⟨map,path⟩:
   sidelen←√(+´⥊' '≠map)÷6
   Pad←{ ⟨h,w⟩←≢𝕩 ⋄ »⍟sidelen˘»⍟sidelen(w+2×sidelen)↑˘(h+2×sidelen)↑𝕩 }
-  •Show map ↩ Pad map
+  map ↩ Pad map
   Move←{
     'L' 𝕊 ⟨pos,dir⟩: ⟨pos,TL dir⟩;
     'R' 𝕊 ⟨pos,dir⟩: ⟨pos,TR dir⟩;
@@ -49,24 +49,30 @@ Main←{𝕊⟨map,path⟩:
     ⟨pos,dir⟩↩CubeWalk ⟨pos-dir,dir⟩ # Step back, walk sideways around edge.
     ⟨pos,-dir⟩ # And then turn around and continue.
   }
-  CubeWalk←{𝕊 ⟨pos,dir⟩:
-    •Show map Mark ⟨pos,dir⟩
+  # CubeStep moves from one edge on the boundary of the net to the
+  # next one, returning the new position and orientation and also the
+  # number of faces passed on the way.
+  CubeStep←{𝕊 ⟨pos,dir,nfaces⟩:
     cv←⌈⌾((÷⟜(sidelen×dir+TR dir))∘(0.5⊸+)) pos # Current vertex (ahead/right)
-    •Show cv
     axes←(⊣∾-)⟨[0‿1,1‿0],[1‿0,0‿¯1]⟩
     Reflect←+˝∘×
     dests←{
       ⟨(𝕩⊸Reflect)⌾(-⟜cv) pos, 𝕩 Reflect dir⟩
     }¨axes
-    •Show map⊸Mark¨dests
-    "Excessively interesting vertex" ! 3=+´' '≠(⊑¨dests)⊑map
+    nfaces +↩ +´' '≠(⊑¨dests)⊑map
     # Find destination that is on the map but looking off it.
-    ⊑({𝕊⟨pos,dir⟩:∧´⟨0,1⟩=' '=⟨pos,pos+dir⟩⊑map}¨dests)/dests
+    ⟨pos,dir⟩↩⊑({𝕊⟨pos,dir⟩:∧´⟨0,1⟩=' '=⟨pos,pos+dir⟩⊑map}¨dests)/dests
+    ⟨pos,dir,nfaces⟩  }
+  CubeWalk←{𝕊 ⟨pos,dir⟩:
+    nfaces←0
+    ⟨pos,dir,nfaces⟩ CubeStep↩
+    # Repeatedly explore subtrees and step over faces until we've covered
+    # three faces.
+    2↑CubeStep∘(CubeWalk⌾(2⊸↑)) •_while_ { 𝕊⟨·,·,nfaces⟩: nfaces < 3 } ⟨pos,dir,nfaces⟩
   }
   pos←⟨sidelen,⊑(sidelen⊏map)⊐'.'⟩
   dir←⟨0,1⟩
   ⟨⟨r,c⟩,d⟩ ← ⟨pos,dir⟩ Move´ ⌽path
-  •Show ⟨⟨r,c⟩,d⟩
   (1000×r+1-sidelen) + (4×c+1-sidelen) + (|1-˜+´⟨2,1⟩×d)
 }