Last active
February 6, 2016 19:05
-
-
Save gregjhogan/c9c6d25277e1636497e7 to your computer and use it in GitHub Desktop.
Fibonacci Sequence Calculator
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
| public class Fibinocci | |
| { | |
| public readonly int N; | |
| public Fibinocci(int n) | |
| { | |
| if (n < 0) | |
| { | |
| throw new Exception("n must be >= 0"); | |
| } | |
| this.N = n; | |
| } | |
| public int Calculate() | |
| { | |
| if (this.N == 0) | |
| { | |
| return 0; | |
| } | |
| return Calculate(0, 1, 1); | |
| } | |
| internal int Calculate(int previous, int current, int count) | |
| { | |
| if (count == this.N) | |
| { | |
| return current; | |
| } | |
| return this.Calculate(current, previous + current, ++count); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment