I\'m trying to implement the following function, but it keeps giving me the stack level too deep (SystemStackError) error.
stack level too deep (SystemStackError)
Any ideas what the problem mi
Here is a more concise solution that builds a lookup table:
fibonacci = Hash.new do |hash, key| if key <= 1 hash[key] = key else hash[key] = hash[key - 1] + hash[key - 2] end end fibonacci[10] # => 55 fibonacci # => {1=>1, 0=>0, 2=>1, 3=>2, 4=>3, 5=>5, 6=>8, 7=>13, 8=>21, 9=>34, 10=>55}