Anonymous user
Pythagorean triples: Difference between revisions
Updated D code
(Add Seed7 example) |
(Updated D code) |
||
Line 170:
{{trans|C}}
With the dmd compiler use -L/STACK:10000000 to increase stack size.
<lang d>import std.stdio
// Should be ulong if going to or over 1 billion.
Line 178:
void triples(in xint lim,
in xint a=3, in xint b=4, in xint c=5) nothrow {
if (p > lim)
return;
primitives++;
ntriples += lim / p;
triples(lim, a - 2*b + 2*c, 2*a - b + 2*c, 2*a - 2*b + 3*c);
triples(lim, a + 2*b + 2*c, 2*a + b + 2*c, 2*a + 2*b + 3*c);
triples(lim, -a + 2*b + 2*c, -2*a + b + 2*c, -2*a + 2*b + 3*c);
}
|