Anonymous user
Pythagorean triples: Difference between revisions
Simpler D code
(Updated D code) |
(Simpler D code) |
||
Line 208:
Runtime up to 10_000_000_000: about 72 seconds.
A shorter slower version:
<lang d>import std.stdio, std.range, std.algorithm;
ulong[2] tri(
const ulong l = a + b + c;
if (l > lim) return [0, 0];
ulong[2] r = [1, lim / l];
r[] += tri(lim, a - 2*b + 2*c, 2*a - b + 2*c, 2*a - 2*b + 3*c)[];
r[] += tri(lim, a + 2*b + 2*c, 2*a + b + 2*c, 2*a + 2*b + 3*c)[];
r[] += tri(lim, -a + 2*b + 2*c, -2*a + b + 2*c, -2*a + 2*b + 3*c)[];
return r;
}
|