Heronian triangles: Difference between revisions
Content deleted Content added
m →{{header|REXX}}: added a programming note. |
m →{{header|REXX}}: removed the need for parameter passing. |
||
Line 426: | Line 426: | ||
Also, a fair amount of code was added to optimize the speed (at the expense of program simplicity). |
Also, a fair amount of code was added to optimize the speed (at the expense of program simplicity). |
||
<lang rexx>/*REXX pgm generates primitive Heronian triangles by side length & area.*/ |
<lang rexx>/*REXX pgm generates primitive Heronian triangles by side length & area.*/ |
||
parse arg |
parse arg N first area . /*get optional N (sides). */ |
||
if |
if N=='' then N=200 /*maybe use the default. */ |
||
if first=='' then first= 10 /* " " " " */ |
if first=='' then first= 10 /* " " " " */ |
||
if area=='' then area=210 /* " " " " */ |
if area=='' then area=210 /* " " " " */ |
||
numeric digits max(9, 1+length(sides**4)) /*ensure enough |
numeric digits max(9, 1+length(sides**4)) /*ensure enough dec digits. */ |
||
@pmt=' primitive Heronian triangles' /*define handy-dandy literal*/ |
@pmt=' primitive Heronian triangles' /*define handy-dandy literal*/ |
||
call heronian sides /*invoke sub with max SIDES.*/ |
call heronian sides /*invoke sub with max SIDES.*/ |
||
Line 438: | Line 438: | ||
exit /*stick a fork in it, we're done.*/ |
exit /*stick a fork in it, we're done.*/ |
||
/*──────────────────────────────────HERONIAN subroutine─────────────────*/ |
/*──────────────────────────────────HERONIAN subroutine─────────────────*/ |
||
heronian: |
heronian: @.=.; #=0; minP=9e9; maxP=0; minA=9e9; maxA=0; Ln=length(N) |
||
minP=9e9; maxP=0; minA=9e9; maxA=0; Ln=length(N) |
|||
do a=3 to N |
do a=3 to N |
||
do b=a to N; ab=a+b |
do b=a to N; ab=a+b |