Closest-pair problem: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added/changed comments and whitespace, used a template for the outputs.) |
m (→{{header|REXX}}: added a programming note about the possibility of two points being exactly identical, yielding a minimum distance of zero.) |
||
Line 3,666: | Line 3,666: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Programming note: this REXX version allows two (or more) points to be identical, and will |
|||
<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). */ |
<lang rexx>/*REXX program solves the closest pair of points problem (in two dimensions). */ |
||
parse arg N low high seed . /*obtain optional arguments from the CL*/ |
parse arg N low high seed . /*obtain optional arguments from the CL*/ |
||
Line 3,683: | Line 3,685: | ||
do k=j+1 to N /* ··· point and all the other points.*/ |
do k=j+1 to N /* ··· point and all the other points.*/ |
||
dd=(xj - @x.k)**2 + (yj - @y.k)**2 /*compute squared distance from points.*/ |
dd=(xj - @x.k)**2 + (yj - @y.k)**2 /*compute squared distance from points.*/ |
||
if dd<minDD |
if dd<minDD then parse value dd j k with minDD A B |
||
end /*k*/ /* [↑] needn't take SQRT of DD (yet).*/ |
end /*k*/ /* [↑] needn't take SQRT of DD (yet).*/ |
||
end /*j*/ /* [↑] when done, A & B are the points*/ |
end /*j*/ /* [↑] when done, A & B are the points*/ |
||
Line 3,709: | Line 3,711: | ||
</pre> |
</pre> |
||
{{out|output|text= when using the input of: <tt> 1000 </tt> |
{{out|output|text= when using the input of: <tt> 1000 </tt> |
||
}} |
}} |
||
<pre> |
|||
For 1000 points, the minimum distance between the two points: ══x══ ══y══ is: 5.09901951 |
For 1000 points, the minimum distance between the two points: ══x══ ══y══ is: 5.09901951 |
||
[ 6264, 19103] |
[ 6264, 19103] |