Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,15 @@
void main() @safe {
import std.stdio, std.range, std.algorithm, std.typecons, std.numeric;
enum triples = (in uint n) pure nothrow @safe /*@nogc*/ =>
iota(1, n + 1)
.map!(z => iota(1, z + 1)
.map!(x => iota(x, z + 1).map!(y => tuple(x, y, z))))
.joiner.joiner
.filter!(t => t[0] ^^ 2 + t[1] ^^ 2 == t[2] ^^ 2 && t[].only.sum <= n)
.map!(t => tuple(t[0 .. 2].gcd == 1, t[]));
auto xs = triples(100);
writeln("Up to 100 there are ", xs.count, " triples, ",
xs.filter!q{ a[0] }.count, " are primitive.");
}

View file

@ -0,0 +1,17 @@
ulong[2] tri(ulong lim, ulong a=3, ulong b=4, ulong c=5)
pure nothrow @safe @nogc {
immutable l = a + b + c;
if (l > lim)
return [0, 0];
typeof(return) 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;
}
void main() /*@safe*/ {
import std.stdio;
foreach (immutable p; 1 .. 9)
writeln(10 ^^ p, ' ', tri(10 ^^ p));
}

View file

@ -0,0 +1,18 @@
import std.stdio, core.simd;
ulong2 tri(in ulong lim, in ulong a=3, in ulong b=4, in ulong c=5)
pure nothrow @safe @nogc {
immutable l = a + b + c;
if (l > lim)
return [0, 0];
typeof(return) 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;
}
void main() /*@safe*/ {
foreach (immutable p; 1 .. 9)
writeln(10 ^^ p, ' ', tri(10 ^^ p).array);
}

View file

@ -0,0 +1,40 @@
import std.stdio;
alias Xuint = uint; // ulong if going over 1 billion.
__gshared Xuint nTriples, nPrimitives, limit;
void countTriples(Xuint x, Xuint y, Xuint z) nothrow @nogc {
while (true) {
immutable p = x + y + z;
if (p > limit)
return;
nPrimitives++;
nTriples += limit / p;
auto t0 = x - 2 * y + 2 * z;
auto t1 = 2 * x - y + 2 * z;
auto t2 = t1 - y + z;
countTriples(t0, t1, t2);
t0 += 4 * y;
t1 += 2 * y;
t2 += 4 * y;
countTriples(t0, t1, t2);
z = t2 - 4 * x;
y = t1 - 4 * x;
x = t0 - 2 * x;
}
}
void main() {
foreach (immutable p; 1 .. 9) {
limit = Xuint(10) ^^ p;
nTriples = nPrimitives = 0;
countTriples(3, 4, 5);
writefln("Up to %11d: %11d triples, %9d primitives.",
limit, nTriples, nPrimitives);
}
}