Anonymous user
Closest-pair problem: Difference between revisions
m
→{{header|REXX}}: changed/added comments and whitespace, changed indentations, optimized the function and also the multiple IF statement.
(→{{header|Elixir}}: add recursive version) |
m (→{{header|REXX}}: changed/added comments and whitespace, changed indentations, optimized the function and also the multiple IF statement.) |
||
Line 3,217:
=={{header|REXX}}==
<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*/
if N=='' | N==
if low=='' | low==
if high=='' | high==
if datatype(seed,'W') then call random ,,seed
w=length(high); w=w + (w//2==0)
/*╔══════════════════════╗*/
/*║ generate N points. ║*/
/*╚══════════════════════╝*/
end /*j*/ /*X and Y make the point*/
A=1; B=2
minDD=(@x.A-@x.B)**2 + (@y.A-@y.B)**2 /*distance between the first two points
do j=1 for N-1 /*find minimum distance between a ··· */
do k=j+1 to N /* ··· point and all the other points.*/
dd=(@x.j - @x.k)**2 + (@y.j - @y.k)**2 /*compute squared distance from points.*/
if dd
end /*k*/ /* [+] needn't take SQRT of DD (yet).*/
end /*j*/ /* [↑] when done, A & B are the ones*/
_= 'For ' N " points, the minimum distance between the two points: "
say _ center("x", w, '═')" " center('y', w, "═") ' is: ' sqrt(abs(minDD))/1
say left('', length(_)-1)
say left('', length(_)-1)
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
sqrt: procedure; parse arg x;
numeric digits
return g</lang>
'''output''' when using the input of: <tt> 200 </tt>
<pre>
|