Fibonacci Number Series

For this kata, we are going to be writing a small program which prints out the Fibonacci series up to a certain n. For those who do not know, the Fibonacci series is a number series which for any arbitrary n greater than 1 in the series, that n is equal to the sum of the previous two in the series. In a more mathematical notation, this series would look something like: n = n_n-1 + n_n-2. The values for this series up to n = 10 would be, 0, 1, 1, 2, 3, 5, 8, 13, 21, 34.

This kata is a simple problem for most to try solving so it is probably a good one for beginners. Most of the work required is simply arithmetic but there are some things to consider before beginning. First of all, this number series is one of the better ways of introducing recursion into a learning environment because of how remarkably easy it is to simply pass the desired n to the function and then inside of the function to return the sum n minus one and n minus two. This method requires only two conditions, where the value for n equals zero or one. Alternately, this same problem is also used to show how easy it is to convert an iterative function into a recursive function. The easy way of implementi ngthis within a loop would be to use two variables which are initially set to zero and one respectively, set one equal to the sum of the two and swap the values. However, there probably quite a few other solutions, one interesting approach would involve a stack or some similar structure with two values in it initially. What is not an acceptable solution however, is a solution which records values in a table and prints out the nth value in that table.

Similar to the Fibonacci series is the Pell and Jacob number series which involve performing arithmetic operations on the values of n_-1 and n_-2.