From: Ben Harris Date: Sat, 1 Jun 2024 16:49:48 +0000 (+0100) Subject: 22b: pad map so we can detect falling off X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=186a3c2f70c01e4bb68ac9d5701bb576ac9f5b60;p=aoc-2022.git 22b: pad map so we can detect falling off --- diff --git a/22/22b.bqn b/22/22b.bqn new file mode 100644 index 0000000..99bbf69 --- /dev/null +++ b/22/22b.bqn @@ -0,0 +1,28 @@ +Pad←{ ⟨h,w⟩←≢𝕩 ⋄ »˘»(2+w)↑˘(2+h)↑𝕩 } +PrepMap←{ Pad >(⌈´≠¨𝕩)⊸↑¨𝕩 } +PrepStep←{ 𝕊"L": 'L'; 𝕊"R": 'R'; •ParseFloat 𝕩 } +PrepPath←{ PrepStep¨(+`⟨0⟩∾≠˝⍉2↕𝕩∊"LR")⊔𝕩 } +Prep←{ ⟨ PrepMap ¯2↓𝕩, PrepPath ¯1⊑𝕩 ⟩ } + +Mark←{map𝕊⟨pos,dir⟩: + ({𝕊⟨0,1⟩:'>';𝕊⟨1,0⟩:'v';𝕊⟨0,¯1⟩:'<';𝕊⟨¯1,0⟩:'^'}dir)⌾(pos⊸⊑) map +} + +Main←{𝕊⟨map,path⟩: + Move←{ + 'L' 𝕊 ⟨pos,dir⟩: ⟨pos,⟨¯1,1⟩×⌽dir⟩; + 'R' 𝕊 ⟨pos,dir⟩: ⟨pos,⟨1,¯1⟩×⌽dir⟩; + n 𝕊 ⟨pos,dir⟩: ⟨dir Advance⍟n pos,dir⟩ + } + Advance←{dir 𝕊 pos: + dest←(≢map)|pos+dir + dest↩{ (≢map)|𝕩+dir } •_while_ { ' '=𝕩⊑map } dest + ('.'=dest⊑map)⊑⟨pos,dest⟩ + } + pos←⟨1,⊑(1⊏map)⊐'.'⟩ + dir←⟨0,1⟩ + ⟨⟨r,c⟩,d⟩ ← ⟨pos,dir⟩ Move´ ⌽path + (1000×r) + (4×c) + (|1-˜+´⟨2,1⟩×d) +} + +•Show Main Prep •file.Lines ⊑•args