I\'m trying to implement the following function, but it keeps giving me the stack level too deep (SystemStackError) error.
Any ideas what the problem mi
a = [1, 1]
while(a.length < max) do a << a.last(2).inject(:+) end
This will populate a with the series. (You will have to consider the case when max < 2)
If only the nth element is required, You could use Hash.new
fib = Hash.new {|hsh, i| hsh[i] = fib[i-2] + fib[i-1]}.update(0 => 0, 1 => 1)
fib[10]
# => 55