Advertisement
ZaBlanc

Fibonacci 8/23 Fibonacci

Aug 23rd, 2011
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.26 KB | None | 0 0
  1. class Fibonacci
  2.   def self.get_sequence(num)
  3.     if num < 0
  4.       raise ArgumentError.new("Fibonacci sequences must be >= 0")
  5.     elsif num <= 2
  6.       return [1] * num
  7.     end
  8.  
  9.     seq = get_sequence(num - 1)
  10.     return seq + [ seq[-2] + seq[-1] ]
  11.   end
  12. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement