From 1bbff1443623618d7e00bce2d6873e82f38cf686 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Wed, 15 May 2024 15:45:39 +0100 Subject: [PATCH] 15a done --- 15/15a.bqn | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/15/15a.bqn b/15/15a.bqn index b794dfe..a2362b9 100644 --- a/15/15a.bqn +++ b/15/15a.bqn @@ -12,4 +12,20 @@ Prep←{ •ParseFloat¨⟨sx,sy,bx,by⟩ } -•Show Prep¨ •file.Lines ⊑•args +Main←{row𝕊data: + data + s←2↑˘data # Sensors + b←2↓˘data # Beacons + m←+´˘|s-b # Distances to nearest beacons + w←m-|row-1↓˘s # Sideways extent at our row + r←⥊(⥊w≥0)/∾˘´{l←(1↑˘s)𝕏w}¨⟨-,1⊸+⊸+⟩ # Ranges excluded by each sensor + g←⍋r + d←+`(2|g)⊏⟨1,¯1⟩ # Number of sensors excluding each segment of row + x0←(0=»d)/g⊏r # Low x-coordinates or excluded segments + x1←(0=d)/g⊏r # High ditto + n←+´x1-x0 + # Now exclude beacons _on_ this row. Note b may contain duplicates. + n - (+´row=⥊1↓˘∊⊸/b) +} + +•Show (•ParseFloat 1⊑•args)Main >Prep¨ •file.Lines ⊑•args -- 2.30.2