Anonymous user
Closest-pair problem: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments.
(Closest-pair problem en Yabsic) |
m (→{{header|REXX}}: added/changed whitespace and comments.) |
||
Line 4,191:
<br>manifest itself as a minimum distance of zero (the variable <big> <tt> '''dd''' </tt> </big> on line 17).
<lang rexx>/*REXX program solves the closest pair of points problem (in two dimensions). */
parse arg N
if
if
if
if datatype(seed, 'W') then call random ,,seed /*seed for RANDOM (BIF) repeatability.*/
w= length(
/*╔══════════════════════╗*/ do j=1 for N /*generate N random points*/
/*║ generate N points. ║*/ @x.j= random(
/*╚══════════════════════╝*/ @y.j= random(
end /*j*/ /*X & Y make the point.*/
/* [↓] use of XJ & YJ speed things up.*/
do j=1 for N-1; xj= @x.j; yj= @y.j /*find minimum distance between a ··· */
do k=j+1 for N-j-1 /* ··· point and all the other points.*/
if
end /*k*/ /* [↑] needn't take SQRT of
end /*j*/ /* [↑] when done, A & B are the points*/
$= 'For ' N " points, the minimum distance between the two points: "
say $ center("x", w, '═')" "
say left('', length($) - 1)
say left('', length($) - 1)
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
|