Heronian triangles: Difference between revisions

Content deleted Content added
m →‎{{header|REXX}}: optimized the hisqrt function for this task.
m →‎{{header|REXX}}: condensed two generic functions, added a comment, optimized the hisqrt function.
Line 1,398:
end /*a*/
return # /*return # of Heronian triangles.*/
/*──────────────────────────────────HGCD subroutine─────────────────────subroutine──────────────────────────────────────────────────────────────────────*/
hGCD: procedure; parse arg x; do j=2 for 2; /*suby=arg(j); handles exactlydo 3 args*until y==0; parse value x//y y with y x; end; end; return x
/*──────────────────────────────────HISQRT subroutine────────────────────────────────────────────────────────────────────*/
y=arg(j); do until y==0; parse value x//y y with y x; end; end; return x
hIsqrt: procedure; parse arg x; q=1 /*x=x%1; if x==0|x==1 then return x*/ /*◄──note these 2 commented statements.*/
/*──────────────────────────────────HISQRT subroutine───────────────────*/
hIsqrt:do procedurewhile q<=x; parseq=q*4; argend; xr=0; do while q=>1; q=q%4; /*x_=x-r-q; r=r%12; if x=_>=0|x==1 then returnparse value _ r+q with x*/ r; end; return r
/*──────────────────────────────────SHOW subroutine─────────────────────subroutine────────────────────────────────────*/
do while q<=x; q=q*4; end; r=0 /*Q will be > X at loop end.*/
do while q>1 ; q=q%4; _=x-r-q; r=r%2; if _>=0 then do;x=_;r=r+q;end; end
return r /* R is a positive integer.*/
/*──────────────────────────────────SHOW subroutine─────────────────────*/
show: m=0; say; say; parse arg ae; say arg(2); if ae\=='' then first=9e9
say; $=left('',9) /* [↓] skip the nothings. */