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