RosettaCodeData/Task/Closest-pair-problem/J/closest-pair-problem-1.j

5 lines
316 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
vecl =: +/"1&.:*: NB. length of each vector
dist =: <@:vecl@:({: -"1 }:)\ NB. calculate all distances among vectors
minpair=: ({~ > {.@($ #: I.@,)@:= <./@;)dist NB. find one pair of the closest points
closestpairbf =: (; vecl@:-/)@minpair NB. the pair and their distance