From: Ben Harris Date: Tue, 14 May 2024 12:16:38 +0000 (+0100) Subject: 14a: map constructed X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~bjharris/git?a=commitdiff_plain;h=5854d410a9335b68928413d81cbefae3a614c652;p=aoc-2022.git 14a: map constructed --- diff --git a/14/14a.bqn b/14/14a.bqn index 3d5a350..407a672 100644 --- a/14/14a.bqn +++ b/14/14a.bqn @@ -1,2 +1,35 @@ +Split←{ + blocknums ← +`𝕨 + # Set entries in blocknums to -1 when they correspond with delimiters. + blocknums ↩ (¯1¨)⌾(𝕨⊸/) blocknums + blocknums⊔𝕩 +} + _and_and_←{𝕨𝔽◶⟨0,𝕘⟩𝕩} _or_or_ ←{𝕨𝔽◶⟨𝕘,1⟩𝕩} + +Prep←{𝕊 lines: + { + fields←(⊑∘∊⟜" ->"¨𝕩) Split 𝕩 # Ewww + fields↩(0=4|↕≠fields)/fields + { + •ParseFloat¨(','=𝕩)Split𝕩 + }¨fields + }¨lines +} + +RectIndices←{ + i←>𝕨⋈𝕩 + (⌊˝i)⊸+¨⥊↕(1+⌈˝i)-(⌊˝i) +} + +Plot←{ + # Assume all co-ordinates are positive. + map←(1+⌈˝>∾𝕩)⥊0 + {𝕊⟨from,to⟩: + map ↩ 1¨⌾((from RectIndices to)⊸⊑) map + }˘∾2↕¨𝕩 + map⊏".#" +} + +•Show Plot Prep •file.Lines ⊑•args