chiark / gitweb /
15b done
authorBen Harris <bjh21@bjh21.me.uk>
Tue, 21 May 2024 09:08:29 +0000 (11:08 +0200)
committerBen Harris <bjh21@bjh21.me.uk>
Tue, 21 May 2024 09:08:29 +0000 (11:08 +0200)
Utter mess with lots of debugging, which I've left in for posterity.

15/15b.bqn

index 3aaf97df88c3005179c07cc4d52bfe8e105db667..529b8ff97ddcf219db834169e16386d6b2d42184 100644 (file)
@@ -18,7 +18,27 @@ Main←{𝕊data:
   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.
+  csp←(<⌜˜↕≠s)∧2=dt-mt # Sensor pairs that are just the right distance apart.
+  cspi←(⥊csp)/⥊↕≢csp # ... as pairs of indices
+  "Wrong number of results" ! 2=≠cspi
+  •Show cspi
+  {
+    •Show {𝕩⊏s}¨𝕩
+    •Show ⟨+´|-´{𝕩⊏s}¨𝕩,(⊑𝕩)⊑m,(1⊑𝕩)⊑m,((⊑𝕩)⊑m)+((1⊑𝕩)⊑m)⟩
+  }¨cspi
+  •Show ls←{⊑(⊏⍋𝕩⊏s)⊏𝕩}¨cspi # Left-most sensor IDs
+  •Show ⟨tls,bls⟩←(⍋1↓˘ls⊏s)⊏ls
+  yi0←1++´⟨0,tls⊑m⟩+tls⊏s # Y intercept of /-diagonal line of solutions
+  yi1←1-˜-˜´⟨0,-bls⊑m⟩+bls⊏s # Ditto for \-diagonal
+  x←(yi0-yi1)÷2
+  y←yi1+x
+  •Show ⟨x,y⟩
+  # Confirming: distances to sensors from proposed location
+  d← {
+    +´|⟨x,y⟩-𝕩
+  }˘s
+  •Show >d⋈¨m
+  y+4000000×x
 }
 
 •Show Main >Prep¨ •file.Lines ⊑•args