Heronian triangles: Difference between revisions

m
→‎using iSQRT: added whitespace, aligned the END with the DO loop.
m (→‎using SQRT table: added whitespace, optimized a DO loop, aligned the END with the DO loop..)
m (→‎using iSQRT: added whitespace, aligned the END with the DO loop.)
Line 3,697:
<lang rexx>/*REXX program generates & displays primitive Heronian triangles by side length and area*/
parse arg N first area . /*obtain optional arguments from the CL*/
if N=='' | N=="," then N=200 200 /*Not specified? Then use the default.*/
if first=='' | first=="," then first= 10 10 /* " " " " " " */
if area=='' | area=="," then area=210 210 /* " " " " " " */
numeric digits 99; numeric digits max(9, 1+length(N**5)) /*ensure 'nuff decimaldec. digitsdigs to calc. N**5.*/
numeric digits max(9, 1 + length(N**5) ) /*minimize decimal digits for REXX pgm.*/
call Heron; HT= 'Heronian triangles' /*invoke the Heron subroutine. */
say # ' primitive' HT "found with sides up to " N ' (inclusive).'
Line 3,708 ⟶ 3,709:
/*──────────────────────────────────────────────────────────────────────────────────────*/
Heron: @.= 0; minP= 9e9; maxP= 0; maxA= 0; minA= 9e9; Ln= length(N) /* __*/
#= 0; #.= 0; #.2= 1; #.3= 1; #.7= 1; #.8= 1 /*digits ¬good √ */
do a=3 to N /*start at a minimum side length of 3. */
Aeven= a//2==0 /*if A is even, B and C must be odd.*/
Line 3,727 ⟶ 3,728:
end /*c*/ /* [↑] keep each unique perimeter#*/
end /*b*/
end /*a*/; return # /*return # of Heronian triangles. */
/*─────────────────────────────────────────────────────────────────────────────────────────────*/
hGCD: x=a; do j=2 for 2; y=arg(j); do until y==0; parse value x//y y with y x; end; end; return x
/*──────────────────────────────────────────────────────────────────────────────────────*/
hIsqrthGCD: procedurex=a; parse arg x;do qj=12 for 2; r y=0 arg(j); do while q<=x; do quntil y=q*4=0; parse end;value x//y y with doy while q>1x
q=q%4; _=x-r-q; r=r%2; if _>=0 then parse value _ r+q with x r; end; return r end /*until*/
end /*j*/; return x
/*──────────────────────────────────────────────────────────────────────────────────────*/
hIsqrt: procedure; parse arg x; q= 1; r= 0; do while q<=x; q= q * 4
end /*while q<=x*/
do while q>1; q=q%4; _= x-r-q; r= r%2; if _>=0 then parse value _ r+q with x r
end /*while q>1*/; return r
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: m=0; say; say; parse arg ae; say arg(2); if ae\=='' then first= 9e9