Closest-pair problem: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added/changed whitespace and comments.) |
m (→{{header|REXX}}: added whitespace.) |
||
Line 4,197: | Line 4,197: | ||
if datatype(seed, 'W') then call random ,,seed /*seed for RANDOM (BIF) repeatability.*/ |
if datatype(seed, 'W') then call random ,,seed /*seed for RANDOM (BIF) repeatability.*/ |
||
w= length(HI); w= w + (w//2==0) /*W: for aligning the output columns.*/ |
w= length(HI); w= w + (w//2==0) /*W: for aligning the output columns.*/ |
||
/*╔══════════════════════╗*/ do j=1 for N /*generate N random points*/ |
/*╔══════════════════════╗*/ do j=1 for N /*generate N random points*/ |
||
/*║ generate N points. ║*/ @x.j= random(LO, HI) /* " a " X */ |
/*║ generate N points. ║*/ @x.j= random(LO, HI) /* " a " X */ |
||
Line 4,204: | Line 4,205: | ||
minD= (@x.A - @x.B)**2 + (@y.A - @y.B)**2 /* distance between the 1st two points.*/ |
minD= (@x.A - @x.B)**2 + (@y.A - @y.B)**2 /* distance between the 1st two points.*/ |
||
/* [↓] use of XJ & YJ speed things up.*/ |
/* [↓] use of XJ & YJ speed things up.*/ |
||
do j=1 for N-1; xj= @x.j; yj= @y.j /*find |
do j=1 for N-1; xj= @x.j; yj= @y.j /*find min distance between a point ···*/ |
||
do k=j+1 for N-j-1 /* ··· |
do k=j+1 for N-j-1 /* ··· and all other (higher) points. */ |
||
sd= (xj - @x.k)**2 + (yj - @y.k)**2 /*compute squared distance from points.*/ |
sd= (xj - @x.k)**2 + (yj - @y.k)**2 /*compute squared distance from points.*/ |
||
if sd<minD then parse value sd j k with minD A B |
if sd<minD then parse value sd j k with minD A B |