Created
November 30, 2013 04:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio; | |
template Fibonacci(int n) { | |
static if (n == 0) | |
const Fibonacci = 0; | |
else static if(n == 1) | |
const Fibonacci = 1; | |
else static if(n == -1) | |
const Fibonacci = 1; | |
else static if(n > 1) | |
const Fibonacci = Fibonacci!(n - 1) + Fibonacci!(n - 2); | |
else | |
const Fibonacci = Fibonacci!(n + 2) - Fibonacci!(n + 1); | |
} | |
void main() { | |
Fibonacci!(0).writeln; | |
Fibonacci!(-1).writeln; | |
Fibonacci!(-2).writeln; | |
Fibonacci!(-3).writeln; | |
Fibonacci!(-9).writeln; | |
Fibonacci!(-10).writeln; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment