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⟩;
⟨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)
}