RosettaCodeData/Task/Closest-pair-problem/J/closest-pair-problem-1.j
2023-07-01 13:44:08 -04:00

4 lines
316 B
Text

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