Friday, March 1, 2013

Number of Triples to...

1
2
3
4
5
6
7
8
Up to 10: 0 triples, 0 primitives.
Up to 100: 17 triples, 7 primitives.
Up to 1000: 325 triples, 70 primitives.
Up to 10000: 4858 triples, 703 primitives.
Up to 100000: 64741 triples, 7026 primitives.
Up to 1000000: 808950 triples, 70229 primitives.
Up to 10000000: 9706567 triples, 702309 primitives.
Up to 100000000: 113236940 triples, 7023027 primitives.
 By Paul and Vikram using C because we're just that good.
Take that Harry and Josh


typedef unsigned long xint;

xint total, prim, max_peri;
xint U[][9] =  {{ 1, -2, 2,  2, -1, 2,  2, -2, 3},
{ 1,  2, 2,  2,  1, 2,  2,  2, 3},
{-1,  2, 2, -2,  1, 2, -2,  2, 3}};
void new_tri(xint in[])
{
int i;
xint t[3], p = in[0] + in[1] + in[2];
if (p > max_peri) return;
prim ++;

total += max_peri / p;
for (i = 0; i < 3; i++) {
t[0] = U[i][0] * in[0] + U[i][1] * in[1] + U[i][2] * in[2];
t[1] = U[i][3] * in[0] + U[i][4] * in[1] + U[i][5] * in[2];
t[2] = U[i][6] * in[0] + U[i][7] * in[1] + U[i][8] * in[2];
new_tri(t);
}
}
int main()
{
xint seed[3] = {3, 4, 5};
for (max_peri = 10; max_peri <= 100000000; max_peri *= 10) {
total = prim = 0;
new_tri(seed);
printf( "Up to "FMT": "FMT" triples, "FMT" primitives.\n",
max_peri, total, prim);
}
return 0;
}

5 comments:

  1. Can I see the code?

    ReplyDelete
  2. Replies
    1. We edited it, and made it our own.

      Delete
  3. http://rosettacode.org/wiki/Pythagorean_triples

    Take that Vik and Paul

    ReplyDelete
  4. And the truth floweth forth

    ReplyDelete