Heronian triangles: Difference between revisions

m
→‎using SQRT table: added whitespace, optimized a DO loop, aligned the END with the DO loop..
m (→‎{{header|Perl 6}}: added .race for concurrency)
m (→‎using SQRT table: added whitespace, optimized a DO loop, aligned the END with the DO loop..)
Line 3,790:
/*──────────────────────────────────────────────────────────────────────────────────────*/
Heron: @.= 0; #= 0; !.= .; minP= 9e9; maxA= 0; maxP= 0; minA= 9e9; Ln= length(N)
do i=51 tofor N**2 % 2; _= i*i; !._= i /* __ */
end /*i*/ /* [↑] pre─calculate some fast √ */
do a=3 to N /*start at a minimum side length of 3. */
Line 3,803:
#= # + 1; p= ab + c; ar= !._ /*primitive Heronian triangle*/
minP= min( p, minP); maxP= max( p, maxP); Lp= length(maxP)
minA= min(ar, minA); maxA= max(ar, maxA); La= length(maxA); @.ar=
_= @.ar.p.0 + 1 /*bump the triangle counter. */
@.ar.p.0= _; @.ar.p._= right(a, Ln) right(b, Ln) right(c, Ln) /*unique*/
Line 3,809:
end /*b*/
end /*a*/; return # /*return number 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
end /*until*/
end /*j*/; return x
/*──────────────────────────────────────────────────────────────────────────────────────*/
show: m=0; say; say; parse arg ae; say arg(2); if ae\=='' then first= 9e9