Anonymous user
Pythagorean triples: Difference between revisions
Improved D code
(added Fortran) |
(Improved D code) |
||
Line 177:
__gshared xint total, prim;
void triples(in xint
in xint
static enum xint[9][3] U = [[ 1, -2, 2, 2, -1, 2, 2, -2, 3],
[ 1, 2, 2, 2, 1, 2, 2, 2, 3],
Line 193:
// recursively produce next tier by multiplying the matrices
foreach (i; TypeTuple!(0, 1, 2))
triples(
U[i][0] * in0 + U[i][1] * in1 + U[i][2] * in2,
U[i][3] * in0 + U[i][4] * in1 + U[i][5] * in2,
U[i][6] * in0 + U[i][7] * in1 + U[i][8] * in2
}
Line 202:
foreach (p; 1 .. 10) {
total = prim = 0;
triples(
writefln("Up to %10d: %10d triples, %8d primitives.",
10 ^^ p, total, prim);
|