chiark / gitweb /
15a done
authorBen Harris <bjh21@bjh21.me.uk>
Wed, 15 May 2024 14:45:39 +0000 (15:45 +0100)
committerBen Harris <bjh21@bjh21.me.uk>
Wed, 15 May 2024 14:45:39 +0000 (15:45 +0100)
15/15a.bqn

index b794dfe09835cbf02ff73288fbaa4d625a5e611d..a2362b9211c037227a7794a7d6dfffd894ce537a 100644 (file)
@@ -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