A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
14
Task/Man-or-boy-test/D/man-or-boy-test-1.d
Normal file
14
Task/Man-or-boy-test/D/man-or-boy-test-1.d
Normal 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));
|
||||
}
|
||||
14
Task/Man-or-boy-test/D/man-or-boy-test-2.d
Normal file
14
Task/Man-or-boy-test/D/man-or-boy-test-2.d
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import std.stdio;
|
||||
|
||||
int A(int k, int delegate()[] x ...) {
|
||||
int b() {
|
||||
k--;
|
||||
return A(k, &b, x[0], x[1], x[2], x[3]);
|
||||
}
|
||||
|
||||
return (k <= 0) ? x[3]() + x[4]() : b();
|
||||
}
|
||||
|
||||
void main() {
|
||||
writeln(A(10, 1, -1, -1, 1, 0));
|
||||
}
|
||||
28
Task/Man-or-boy-test/D/man-or-boy-test-3.d
Normal file
28
Task/Man-or-boy-test/D/man-or-boy-test-3.d
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import std.stdio;
|
||||
|
||||
int delegate() mb(T)(T mob) { // embeding function
|
||||
int b() {
|
||||
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) {
|
||||
static if (is(T == int)) {
|
||||
return A(k, mb(x1), mb(x2), mb(x3), mb(x4), mb(x5));
|
||||
} else {
|
||||
int b() {
|
||||
k--;
|
||||
return A(k, &b, x1, x2, x3, x4);
|
||||
}
|
||||
return (k <= 0) ? x4() + x5() : b();
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
writeln(A(10, 1, -1, -1, 1, 0));
|
||||
}
|
||||
40
Task/Man-or-boy-test/D/man-or-boy-test-4.d
Normal file
40
Task/Man-or-boy-test/D/man-or-boy-test-4.d
Normal 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));
|
||||
}
|
||||
76
Task/Man-or-boy-test/D/man-or-boy-test-5.d
Normal file
76
Task/Man-or-boy-test/D/man-or-boy-test-5.d
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
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) {
|
||||
switch (k) {
|
||||
case 0: return BigInt(0);
|
||||
case 1: return BigInt(0);
|
||||
case 2: return BigInt(0);
|
||||
case 3: return BigInt(1);
|
||||
case 4: return BigInt(2);
|
||||
case 5: return BigInt(3);
|
||||
default: return c1(k - 1) + c2(k - 1);
|
||||
}
|
||||
}
|
||||
alias memoize!_c1 c1;
|
||||
|
||||
static BigInt _c2(in int k) {
|
||||
switch (k) {
|
||||
case 0: return BigInt(0);
|
||||
case 1: return BigInt(0);
|
||||
case 2: return BigInt(1);
|
||||
case 3: return BigInt(1);
|
||||
case 4: return BigInt(1);
|
||||
case 5: return BigInt(2);
|
||||
default: return c2(k - 1) + c3(k - 1);
|
||||
}
|
||||
}
|
||||
alias memoize!_c2 c2;
|
||||
|
||||
static BigInt _c3(in int k) {
|
||||
switch (k) {
|
||||
case 0: return BigInt(0);
|
||||
case 1: return BigInt(1);
|
||||
case 2: return BigInt(1);
|
||||
case 3: return BigInt(0);
|
||||
case 4: return BigInt(0);
|
||||
case 5: return BigInt(1);
|
||||
default: return c3(k - 1) + c4(k);
|
||||
}
|
||||
}
|
||||
alias memoize!_c3 c3;
|
||||
|
||||
static BigInt _c4(in int k) {
|
||||
switch (k) {
|
||||
case 0: return BigInt(1);
|
||||
case 1: return BigInt(1);
|
||||
case 2: return BigInt(0);
|
||||
case 3: return BigInt(0);
|
||||
case 4: return BigInt(0);
|
||||
case 5: return BigInt(0);
|
||||
default: return c1(k - 1) + c4(k - 1) - 1;
|
||||
}
|
||||
}
|
||||
alias memoize!_c4 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 (i; 0 .. 40)
|
||||
writeln(i, " ", A(i, 1, -1, -1, 1, 0));
|
||||
|
||||
writefln("...\n500 %-(%s\\\n %)",
|
||||
std.range.chunks(dtext(A(500, 1, -1, -1, 1, 0)), 60));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue