Anonymous user
Closest-pair problem: Difference between revisions
→{{header|REXX}}: reworked program, made arrays simplier, changed output format.
(→{{header|Ruby}}: used Array#combination) |
(→{{header|REXX}}: reworked program, made arrays simplier, changed output format.) |
||
Line 2,883:
=={{header|REXX}}==
<lang rexx>/*REXX program solves the closest pair of points problem in 2 dimensions*/
if low=='' | low==',' then low=0
if
if
w=length(high);
do j=1 for N /*gen N random
@x.j
@y.j
end /*j*/
A=1; B=2
minDD=(@x.A-@x.B)**2 + (@y.A-@y.B)**2 /*distance between 1st two points*/
do j=1 for N-1
do k=j+1 to N
nearA=j▼
end /*j*/ /* [↑] when done, A & B are
▲ end /*k*/
say
say left('
say left('', length(_)-1)
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────SQRT subroutine───────────────────────*/
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits();
numeric digits
g=g*.5'E'_%2; m.=11;
do k=j+5 to 0 by -1; if m.k>11 then numeric digits
{{out}} when using the input of: <tt> 200 </tt>▼
▲ parse value format(x,2,1,,0) 'E0' with g 'E' _ .; return g*.5'E'_%2</lang>
▲{{out}} when using the input of: <tt> 200 </tt>
<pre>
For 200 points, the minimum distance between the two points: ══x══ ══y══ is: 39.408121
</pre>
|