Heronian triangles: Difference between revisions
Content deleted Content added
Walterpachl (talk | contribs) m typo 2 |
m →{{header|REXX}}: changed/added some comments and whitespace, resolved cut&paste error, clarified what is being displayed. |
||
Line 508:
Programming note: the '''hGCD''' subroutine is a specialized version of a GCD routine in that it doesn't check for non-positive integers.
Also, a fair amount of code was added to optimize the speed (at the expense of program simplicity).
This REXX program doesn't need to explicitly sort the triangles.
<lang rexx>/*REXX pgm generates primitive Heronian triangles by side length & area.*/
parse arg N first area
if N==''
if
@pht=' primitive Heronian triangles' /*define handy-dandy literal*/
▲numeric digits max(9, 1+length(sides**4)) /*ensure enough dec digits. */
▲say # @pmt 'found with sides up to ' sides " (inclusive)."
call show
▲call show area, 'listing of the'@pmt "with area=" area
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────HERONIAN subroutine─────────────────*/
do a=3 to N /*start at minimum side length.*/
do b=a to N; ab=a+b /*AB: is used for summing below.*/
do c=b to N /* [↓] if GCD ¬=1, it's not a */
if hGCD(a,b,c)\==1 then iterate /* primitive Heronian triangle.*/
Line 532 ⟶ 533:
ar=sqrt(s*_) ; if pos(.,ar)\==0 then iterate /*area¬int.*/
if ar==0 then iterate /*area=zero*/
#=#+1 /*
end /*c*/ /* [↑] keep each unique P items.*/
end /*b*/
end /*a*/
return # /*return # of Heronian triangles.*/
/*──────────────────────────────────HGCD subroutine─────────────────────*/
hGCD: procedure; parse arg x /*this sub handles exactly 2 args*/
do j=2 for 2; y=arg(j); do until _==0; _=x//y; x=y; y=_; end; end
return x
Line 551:
do i=minA to maxA; if @.i==. then iterate /*skip nulls.*/
if ae\=='' & i\==ae then iterate /*Area specified? Then check*/
end /*i*/ /*
return
/*──────────────────────────────────SQRT subroutine─────────────────────────*/
Line 585:
listing of the (above) found primitive Heronian triangles with an area
1 area: 210 perimeter: 70 sides: 17 25 28
|