Closest-pair problem: Difference between revisions

→‎{{header|Maple}}: fixed brute force step to make sure it gets the right sub-set of L
(→‎{{header|Maple}}: First Version)
(→‎{{header|Maple}}: fixed brute force step to make sure it gets the right sub-set of L)
Line 2,293:
 
local
BruteForce := proc(L, Lx, r1:=1, r2:=numelems(L), $)
local d, p, n, i, j;
d := infinity;
for i from r1 to r2-1 do
for j from i+1 to r2 do
n := dist( L[Lx[i]], L[Lx[j]] );
if n < d then
d := n;
p := [ L[Lx[i]], L[Lx[j]] ];
end if;
end do; # j
Line 2,314:
 
if r2-r1 <= 3 then
return BruteForce(L, Lx, r1, r2);
end if;
 
Anonymous user