Fibonacci n-step number sequences
This page is the answer to the task Fibonacci n-step number sequences in the Rosetta Code.
Contents
Description (from Rosetta Code)
These number series are an expansion of the ordinary Fibonacci sequence where:
For small values of
Allied sequences can be generated where the initial values are changed:
The Lucas series sums the two preceding values like the fibonacci series for Task
|
Solution
Main function
According to the requirements, the program must generate a series, and the order (Fibonacci, Tribonacci, etc) should be determined according with the initial values.
In this case, the number n indicates how many terms of the series will be generated.
The following generates a Fibonacci series of 20 terms:
The following generates a Lucas series of 20 terms:
The following generates a Tribonacci series of 20 terms:
Generating initial values
The initial values can be generated by the following function.
Note that it is a recursive function, and it calls the previously defined function. It requires the initial values as a seed, for Fibonacci style (Fibonacci, Tribonacci, etc), and
for Lucas style.
The following generates the initial values for Fibonacci.
The following generates the initial values for Lucas.
Generating tables of series for Fibonacci and Lucas
This generates a tables of series for Fibonacci (25 terms), for orders 2 to 20 (Fibonacci, Tribonacci, etc.)
This generates a tables of series for Lucas (25 terms), for orders 2 to 20