Anonymous user
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=
if first=='' | first=="," then first=
if area=='' | area=="," then area=
numeric digits 99
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) /* __*/
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 #
/*──────────────────────────────────────────────────────────────────────────────────────*/
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
|