2015-02-20 00:35:01 -05:00
|
|
|
int fib(in uint arg) pure nothrow @safe @nogc {
|
|
|
|
|
assert(arg >= 0);
|
2013-10-27 22:24:23 +00:00
|
|
|
|
2015-02-20 00:35:01 -05:00
|
|
|
return function uint(in uint n) pure nothrow @safe @nogc {
|
|
|
|
|
static immutable self = &__traits(parent, {});
|
2013-10-27 22:24:23 +00:00
|
|
|
return (n < 2) ? n : self(n - 1) + self(n - 2);
|
|
|
|
|
}(arg);
|
2013-04-10 16:57:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void main() {
|
2015-02-20 00:35:01 -05:00
|
|
|
import std.stdio;
|
|
|
|
|
|
2013-10-27 22:24:23 +00:00
|
|
|
39.fib.writeln;
|
2013-04-10 16:57:12 -07:00
|
|
|
}
|