Fibonacci sequence in Ruby (recursion)

后端 未结 24 1243
悲&欢浪女
悲&欢浪女 2020-12-01 02:54

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

24条回答
  •  -上瘾入骨i
    2020-12-01 03:41

    i think this is pretty easy:

    def fibo(n) a=0 b=1 for i in 0..n c=a+b print "#{c} " a=b b=c end
    
    end
    

提交回复
热议问题