RosettaCodeData/Task/Closest-pair-problem/J/closest-pair-problem-1.j
2016-12-05 22:15:40 +01: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