32 lines
835 B
Plaintext
32 lines
835 B
Plaintext
_elements = 9
|
|
|
|
local fn ClosetPairProblem
|
|
long i, j
|
|
double minDist = 1000000
|
|
double dist, minDisti, minDistj
|
|
|
|
double x(_elements), y(_elements)
|
|
x(0) = 0.654682 : y(0) = 0.925557
|
|
x(1) = 0.409382 : y(1) = 0.619391
|
|
x(2) = 0.891663 : y(2) = 0.888594
|
|
x(3) = 0.716629 : y(3) = 0.996200
|
|
x(4) = 0.477721 : y(4) = 0.946355
|
|
x(5) = 0.925092 : y(5) = 0.818220
|
|
x(6) = 0.624291 : y(6) = 0.142924
|
|
x(7) = 0.211332 : y(7) = 0.221507
|
|
x(8) = 0.293786 : y(8) = 0.691701
|
|
x(9) = 0.839186 : y(9) = 0.728260
|
|
|
|
for i = 0 to 8
|
|
for j = i + 1 to 9
|
|
dist = ( x(i) - x(j) )^2 + ( y(i) - y(j) )^2
|
|
if dist < minDist then minDist = dist : minDisti = i : minDistj = j
|
|
next
|
|
next
|
|
print "The closest pair is "; minDisti; " and "; minDistj; " at a distance of "; sqr(minDist)
|
|
end fn
|
|
|
|
fn ClosetPairProblem
|
|
|
|
HandleEvents
|