In this guide, we’ll walk through how to generate the Fibonacci sequence in the Ruby programming language.
Summary
Create a method that generates the Fibonacci sequence.
Exercise File
Exercise Description
Build a method that returns an array of the Fibonacci sequence of a pre-defined number of values.
Sample Process
Definition: Characterized by the fact that every number after the first two is the sum of the two preceding ones.
fibonacci 10
Expected Output
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
Real World Usage
The Fibonacci sequence is a key sequence utilized in a large variety of mathematical equations. Specifically, due to the rapid growth of the Fibonacci sequence, it’s useful when analyzing algorithm performance.
Solution
Can be found on the solutions branch on github.