chiark / gitweb /
15b: found constraining beacons
authorBen Harris <bjh21@bjh21.me.uk>
Wed, 15 May 2024 15:53:02 +0000 (17:53 +0200)
committerBen Harris <bjh21@bjh21.me.uk>
Wed, 15 May 2024 15:53:02 +0000 (17:53 +0200)
15/15b.bqn [new file with mode: 0644]

diff --git a/15/15b.bqn b/15/15b.bqn
new file mode 100644 (file)
index 0000000..3aaf97d
--- /dev/null
@@ -0,0 +1,24 @@
+Split←{
+  blocknums ← +`𝕨
+  # Set entries in blocknums to -1 when they correspond with delimiters.
+  blocknums ↩ (¯1¨)⌾(𝕨⊸/) blocknums
+  blocknums⊔𝕩
+}
+
+Prep←{
+  words←' '⊸=⊸Split 𝕩
+  ⟨sx,sy,bx⟩←2↓¨¯1↓¨⟨2,3,8⟩⊏words
+  by←2↓9⊑words
+  •ParseFloat¨⟨sx,sy,bx,by⟩
+}
+
+Main←{𝕊data:
+  s←2↑˘data # Sensors
+  b←2↓˘data # Beacons
+  m←+´˘|s-b # Distances to nearest beacons
+  mt←m+⌜m   # Sums of excluded ranges
+  dt←(<˘s){+´|𝕨-𝕩}⌜(<˘s) # Distances between sensors
+  2=dt-mt # Beacon pairs that are precisely the right distance apart.
+}
+
+•Show Main >Prep¨ •file.Lines ⊑•args