CDE
This commit is contained in:
parent
518da4a923
commit
764da6cbbb
6144 changed files with 83610 additions and 11 deletions
9
Task/Anonymous-recursion/D/anonymous-recursion-1.d
Normal file
9
Task/Anonymous-recursion/D/anonymous-recursion-1.d
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
uint fib(in uint n) pure nothrow {
|
||||
immutable self = &__traits(parent, {});
|
||||
return (n < 2) ? n : self(n - 1) + self(n - 2);
|
||||
}
|
||||
|
||||
void main() {
|
||||
import std.stdio;
|
||||
writeln(fib(39));
|
||||
}
|
||||
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