By Scott Hale
Fibonacci Quickly find the nth number* in the Fibonacci sequence (1,1 style).
*Note: Because of the recursion used in the calculation, passing a number much bigger than 20 could take quite a while to calculate...not recommended!
require 'fib.rb'
To use Fibonacci, just pass the nth number you're after into the Fib.nth class method
Fib.nth(3) # => 2
Fib.nth(7) # => 13
Within the fib.rb file in the lib folder, class Fib introduces a class method where recursion is used to calculate all nth numbers in the sequence (except for the first & second numbers: 1 and 1).
- Scott Hale (bozcotty)
- Sunny Mittal (sunny-mittal)
- http://meowist.github.io/blog/2013/03/02/fibonacci-meets-ruby/