From: Ben Harris Date: Thu, 6 Jun 2024 14:07:52 +0000 (+0100) Subject: 22b done X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=f371213108514e5ca30fdb86e098e9ab452086c0;p=aoc-2022.git 22b done First time it ran to completion, it gave the right answer --- diff --git a/22/22b.bqn b/22/22b.bqn index a9dfbfd..8687d7e 100644 --- a/22/22b.bqn +++ b/22/22b.bqn @@ -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) }