Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Anonymous-recursion/D/anonymous-recursion-1.d
Normal file
14
Task/Anonymous-recursion/D/anonymous-recursion-1.d
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
int fib(in uint arg) pure nothrow @safe @nogc {
|
||||
assert(arg >= 0);
|
||||
|
||||
return function uint(in uint n) pure nothrow @safe @nogc {
|
||||
static immutable self = &__traits(parent, {});
|
||||
return (n < 2) ? n : self(n - 1) + self(n - 2);
|
||||
}(arg);
|
||||
}
|
||||
|
||||
void main() {
|
||||
import std.stdio;
|
||||
|
||||
39.fib.writeln;
|
||||
}
|
||||
18
Task/Anonymous-recursion/D/anonymous-recursion-2.d
Normal file
18
Task/Anonymous-recursion/D/anonymous-recursion-2.d
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import std.stdio;
|
||||
|
||||
int fib(in int n) pure nothrow {
|
||||
assert(n >= 0);
|
||||
|
||||
return (new class {
|
||||
static int opCall(in int m) pure nothrow {
|
||||
if (m < 2)
|
||||
return m;
|
||||
else
|
||||
return opCall(m - 1) + opCall(m - 2);
|
||||
}
|
||||
})(n);
|
||||
}
|
||||
|
||||
void main() {
|
||||
writeln(fib(39));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue