Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,51 @@
struct Ludics(T) {
int opApply(int delegate(in ref T) dg) {
int result;
T[] rotor, taken = [T(1)];
result = dg(taken[0]);
if (result) return result;
for (T i = 2; ; i++) { // Shoud be stopped if T has a max.
size_t j = 0;
for (; j < rotor.length; j++)
if (!--rotor[j])
break;
if (j < rotor.length) {
rotor[j] = taken[j + 1];
} else {
result = dg(i);
if (result) return result;
taken ~= i;
rotor ~= taken[j + 1];
}
}
}
}
void main() {
import std.stdio, std.range, std.algorithm;
// std.algorithm.take can't be used here.
uint[] L;
foreach (const x; Ludics!uint())
if (L.length < 2005)
L ~= x;
else
break;
writeln("First 25 ludic primes:\n", L.take(25));
writefln("\nThere are %d ludic numbers <= 1000.",
L.until!q{ a > 1000 }.walkLength);
writeln("\n2000'th .. 2005'th ludic primes:\n", L[1999 .. 2005]);
enum m = 250;
const triplets = L.filter!(x => x + 6 < m &&
L.canFind(x + 2) && L.canFind(x + 6))
// Ugly output:
//.map!(x => tuple(x, x + 2, x + 6)).array;
.map!(x => [x, x + 2, x + 6]).array;
writefln("\nThere are %d triplets less than %d:\n%s",
triplets.length, m, triplets);
}

View file

@ -0,0 +1,58 @@
struct Ludics(T) {
T[] rotor, taken = [T(1)];
T i;
size_t j;
T front = 1; // = taken[0];
bool running = false;
static immutable bool empty = false;
void popFront() pure nothrow @safe {
if (running)
goto RESUME;
else
running = true;
i = 2;
while (true) {
j = 0;
while (j < rotor.length) {
rotor[j]--;
if (!rotor[j])
break;
j++;
}
if (j < rotor.length) {
rotor[j] = taken[j + 1];
} else {
front = i;
return;
RESUME:
taken ~= i;
rotor ~= taken[j + 1];
}
i++; // Could overflow if T has a max.
}
}
}
void main() {
import std.stdio, std.range, std.algorithm, std.array;
Ludics!uint L;
writeln("First 25 ludic primes:\n", L.take(25));
writefln("\nThere are %d ludic numbers <= 1000.",
L.until!q{ a > 1000 }.walkLength);
writeln("\n2000'th .. 2005'th ludic primes:\n", L.drop(1999).take(6));
enum uint m = 250;
const few = L.until!(x => x > m).array;
const triplets = few.filter!(x => x + 6 < m && few.canFind(x + 2)
&& few.canFind(x + 6))
// Ugly output:
//.map!(x => tuple(x, x + 2, x + 6)).array;
.map!(x => [x, x + 2, x + 6]).array;
writefln("\nThere are %d triplets less than %d:\n%s",
triplets.length, m, triplets);
}

View file

@ -0,0 +1,42 @@
void main() {
import std.stdio, std.range, std.algorithm, std.concurrency;
Generator!T ludics(T)() {
return new typeof(return)({
T[] rotor, taken = [T(1)];
yield(taken[0]);
for (T i = 2; ; i++) { // Shoud be stopped if T has a max.
size_t j = 0;
for (; j < rotor.length; j++)
if (!--rotor[j])
break;
if (j < rotor.length) {
rotor[j] = taken[j + 1];
} else {
yield(i);
taken ~= i;
rotor ~= taken[j + 1];
}
}
});
}
const L = ludics!uint.take(2005).array;
writeln("First 25 ludic primes:\n", L.take(25));
writefln("\nThere are %d ludic numbers <= 1000.",
L.until!q{ a > 1000 }.walkLength);
writeln("\n2000'th .. 2005'th ludic primes:\n", L[1999 .. 2005]);
enum m = 250;
const triplets = L.filter!(x => x + 6 < m &&
L.canFind(x + 2) && L.canFind(x + 6))
// Ugly output:
//.map!(x => tuple(x, x + 2, x + 6)).array;
.map!(x => [x, x + 2, x + 6]).array;
writefln("\nThere are %d triplets less than %d:\n%s",
triplets.length, m, triplets);
}