RosettaCodeData/Task/Closest-pair-problem/PL-I/closest-pair-problem.pli
2023-07-01 13:44:08 -04:00

32 lines
1,000 B
Text

/* Closest Pair Problem */
closest: procedure options (main);
declare n fixed binary;
get list (n);
begin;
declare 1 P(n),
2 x float,
2 y float;
declare (i, ii, j, jj) fixed binary;
declare (distance, min_distance initial (0) ) float;
get list (P);
min_distance = sqrt( (P.x(1) - P.x(2))**2 + (P.y(1) - P.y(2))**2 );
ii = 1; jj = 2;
do i = 1 to n;
do j = 1 to n;
distance = sqrt( (P.x(i) - P.x(j))**2 + (P.y(i) - P.y(j))**2 );
if distance > 0 then
if distance < min_distance then
do;
min_distance = distance;
ii = i; jj = j;
end;
end;
end;
put skip edit ('The minimum distance ', min_distance,
' is between the points [', P.x(ii),
',', P.y(ii), '] and [', P.x(jj), ',', P.y(jj), ']' )
(a, f(6,2));
end;
end closest;