From: Ben Harris Date: Tue, 4 Jun 2024 13:41:34 +0000 (+0100) Subject: 22b: move padding into Main and pad much more X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=185895f833afb7d9562c50cb569add65a92226f9;p=aoc-2022.git 22b: move padding into Main and pad much more I'm going to want a whole face's worth of padding all round, and at the moment only Main knows how big the faces are. --- diff --git a/22/22b.bqn b/22/22b.bqn index e63865d..ce191a8 100644 --- a/22/22b.bqn +++ b/22/22b.bqn @@ -1,5 +1,4 @@ -Pad←{ ⟨h,w⟩←≢𝕩 ⋄ »˘»(2+w)↑˘(2+h)↑𝕩 } -PrepMap←{ Pad >(⌈´≠¨𝕩)⊸↑¨𝕩 } +PrepMap←{ >(⌈´≠¨𝕩)⊸↑¨𝕩 } PrepStep←{ 𝕊"L": 'L'; 𝕊"R": 'R'; •ParseFloat 𝕩 } PrepPath←{ PrepStep¨(+`⟨0⟩∾≠˝⍉2↕𝕩∊"LR")⊔𝕩 } Prep←{ ⟨ PrepMap ¯2↓𝕩, PrepPath ¯1⊑𝕩 ⟩ } @@ -12,6 +11,9 @@ TL←{⟨¯1,1⟩×⌽𝕩} TR←{⟨1,¯1⟩×⌽𝕩} Main←{𝕊⟨map,path⟩: + sidelen←√(+´⥊' '≠map)÷6 + Pad←{ ⟨h,w⟩←≢𝕩 ⋄ »⍟sidelen˘»⍟sidelen(w+2×sidelen)↑˘(h+2×sidelen)↑𝕩 } + map ↩ Pad map Move←{ 'L' 𝕊 ⟨pos,dir⟩: ⟨pos,TL dir⟩; 'R' 𝕊 ⟨pos,dir⟩: ⟨pos,TR dir⟩; @@ -22,10 +24,10 @@ Main←{𝕊⟨map,path⟩: dest↩{ (≢map)|𝕩+dir } •_while_ { ' '=𝕩⊑map } dest ⟨('.'=dest⊑map)⊑⟨pos,dest⟩,dir⟩ } - pos←⟨1,⊑(1⊏map)⊐'.'⟩ + pos←⟨sidelen,⊑(sidelen⊏map)⊐'.'⟩ dir←⟨0,1⟩ ⟨⟨r,c⟩,d⟩ ← ⟨pos,dir⟩ Move´ ⌽path - (1000×r) + (4×c) + (|1-˜+´⟨2,1⟩×d) + (1000×r+1-sidelen) + (4×c+1-sidelen) + (|1-˜+´⟨2,1⟩×d) } •Show Main Prep •file.Lines ⊑•args