Anonymous user
Closest-pair problem: Difference between revisions
m
→{{header|REXX}}: added/changed comments and whitespace, used a template for the outputs.
m (→{{header|C++}}) |
m (→{{header|REXX}}: added/changed comments and whitespace, used a template for the outputs.) |
||
Line 3,668:
<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=="," then N=
if low=='' | low=="," then low=
if high=='' | high=="," then high=
if datatype(seed, 'W')
w=length(high); w=w + (w//2==0) /*W: for aligning the output columns.*/
A=1; B=2
minDD= (@x.A - @x.B)**2 + (@y.A - @y.B)**2
/* [↓] use of XJ & YJ speed things up.*/
$= 'For ' N " points, the minimum distance between the two points: "
say $ center("x",
say
say left('', length(
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); m.=9; numeric form; h=d+6
numeric digits; parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g=g *.5'e'_ % 2
▲'''output''' when using the default input of: <tt> 100 </tt>
<pre>
For 100 points, the minimum distance between the two points: ══x══ ══y══ is: 219.228192
Line 3,704 ⟶ 3,702:
[ 7483, 1700]
</pre>
<pre>
For 200 points, the minimum distance between the two points: ══x══ ══y══ is: 39.408121
Line 3,710 ⟶ 3,708:
[17627, 19198]
</pre>
}}<pre>
For 1000 points, the minimum distance between the two points: ══x══ ══y══ is: 5.09901951
[ 6264, 19103]
|