Heronian triangles: Difference between revisions

m
→‎{{header|REXX}}: elided some unneeded REXX statements.
m (→‎{{header|REXX}}: changed some comments in the REXX section header.)
m (→‎{{header|REXX}}: elided some unneeded REXX statements.)
Line 1,374:
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────HERON subroutine────────────────────*/
Heron: @.=.0; #=0; minP=9e9; maxP=0; minA=9e9; maxA=0; Ln=length(N)
#.=0; #.2=1 #.3=1; #.7=1; #.8=1 /*¬good √.*/
do a=3 to N /*start at a minimum side length.*/
Line 1,388:
ar=iSQRT(_); if ar*ar\==_ then iterate /*area ¬ an integer*/
if hGCD(a,b,c)\==1 then iterate /*GCD of sides ¬ 1.*/
#=#+1; p=ab+c /*got prim.primitive H. tri.*/
minP=min( p,minP); maxP=max( p,maxP); Lp=length(maxP)
minA=min(ar,minA); maxA=max(ar,maxA); La=length(maxA); @.ar=
if _=@.ar.p.0==.+1 then @.ar.p.0=0; _=@.ar.p.0+1 /*bump triangle ctr*/
@.ar.p.0=_; @.ar.p._=right(a,Ln) right(b,Ln) right(c,Ln) /*unique*/
end /*c*/ /* [↑] keep each unique P items.*/
Line 1,407:
/*──────────────────────────────────SHOW subroutine─────────────────────*/
show: m=0; say; say; parse arg ae; say arg(2); if ae\=='' then first=9e9
say; y$=left('',9) /* [↓] skip the nothings. */
do i=minA to maxA; if @.i==. then iterate
if ae\=='' & i\==ae then iterate /*Area specified? Then check*/
do j=minP to maxP until m>=first /*only list FIRST entries.*/
if @.i.j.0==. then iterate /*Not defined? Then skip it.*/
do k=1 for @.i.j.0; m=m+1 /*visit each perimeter entry*/
say right(m,9) y$'area:' right(i,La) y$"perimeter:" right(j,Lp) y$'sides:' @.i.j.k
end /*k*/
end /*j*/ /* [↑] use known perimeters*/