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,14 @@
import core.stdc.stdio: printf;
int a(int k, const lazy int x1, const lazy int x2, const lazy int x3,
const lazy int x4, const lazy int x5) pure {
int b() {
k--;
return a(k, b(), x1, x2, x3, x4);
}
return k <= 0 ? x4 + x5 : b();
}
void main() {
printf("%d\n", a(10, 1, -1, -1, 1, 0));
}

View file

@ -0,0 +1,14 @@
int A(int k, int delegate() nothrow @safe[] x...) nothrow @safe {
int b() nothrow @safe {
k--;
return A(k, &b, x[0], x[1], x[2], x[3]);
}
return (k > 0) ? b() : x[3]() + x[4]();
}
void main() {
import std.stdio;
A(10, 1, -1, -1, 1, 0).writeln;
}

View file

@ -0,0 +1,28 @@
auto mb(T)(T mob) nothrow @safe { // Embeding function.
int b() nothrow @safe @nogc {
static if (is(T == int))
return mob;
else
return mob();
}
return &b;
}
int A(T)(int k, T x1, T x2, T x3, T x4, T x5) nothrow @safe {
static if (is(T == int)) {
return A(k, mb(x1), mb(x2), mb(x3), mb(x4), mb(x5));
} else {
int b() nothrow @safe {
k--;
return A(k, &b, x1, x2, x3, x4);
}
return (k <= 0) ? x4() + x5() : b();
}
}
void main() {
import std.stdio;
A(10, 1, -1, -1, 1, 0).writeln;
}

View file

@ -0,0 +1,40 @@
import std.stdio;
interface B {
int run();
}
int A(int k, int x1, int x2, int x3, int x4, int x5) {
B mb(int a) {
return new class() B {
int run() {
return a;
}
};
}
return A(k, mb(x1), mb(x2), mb(x3), mb(x4), mb(x5));
}
int A(int k, B x1, B x2, B x3, B x4, B x5) {
if (k <= 0) {
return x4.run() + x5.run();
} else {
return (new class() B {
int m;
this() {
this.m = k;
}
int run() {
m--;
return A(m, this, x1, x2, x3, x4);
}
}).run();
}
}
void main() {
writeln(A(10, 1, -1, -1, 1, 0));
}

View file

@ -0,0 +1,57 @@
import std.bigint, std.functional;
// Adapted from C code by Goran Weinholt, adapted from Knuth code.
BigInt A(in int k, in int x1, in int x2, in int x3,
in int x4, in int x5) {
static struct Inner {
static BigInt c1_(in int k) {
if (k > 5)
return c1(k - 1) + c2(k - 1);
static immutable t = [0, 0, 0, 1, 2, 3];
return t[k].BigInt;
}
alias c1 = memoize!c1_;
static BigInt c2_(in int k) {
if (k > 5)
return c2(k - 1) + c3(k - 1);
static immutable t = [0, 0, 1, 1, 1, 2];
return t[k].BigInt;
}
alias c2 = memoize!c2_;
static BigInt c3_(in int k) {
if (k > 5)
return c3(k - 1) + c4(k);
static immutable t = [0, 1, 1, 0, 0, 1];
return t[k].BigInt;
}
alias c3 = memoize!c3_;
static BigInt c4_(in int k) {
if (k > 5)
return c1(k - 1) + c4(k - 1) - 1;
static immutable t = [1, 1, 0, 0, 0, 0];
return t[k].BigInt;
}
alias c4 = memoize!c4_;
static int c5(in int k) pure nothrow {
return !!k;
}
}
with (Inner)
return c1(k) * x1 + c2(k) * x2 + c3(k) * x3 +
c4(k) * x4 + c5(k) * x5;
}
void main() {
import std.stdio, std.conv, std.range;
foreach (immutable i; 0 .. 40)
writeln(i, " ", A(i, 1, -1, -1, 1, 0));
writefln("...\n500 %-(%s\\\n %)",
A(500, 1, -1, -1, 1, 0).text.chunks(60));
}