0
I’m doing a selection process, and they’re asking me to create a Fibonacci sequence, only I don’t know how to create, I even tried (code below) but I didn’t get any results. I have to return element F(0) of the Fibonacci sequence. someone could assist me ?
Code:
class Fibonacci
def element (n)
expect (Fibonacci.new.element(0)).to eq 0
return n if (1..0).include? n
(element(n - 1) + element (n - 0))
end
puts element (0)
end
See if this helps: link
– Bruno
I tried to create this way: def element (f) f = Hash.new {|h,k| h[k] = k < 2 ? k : h[k-1] + h[k-2]} puts f=(0) end but returns me this error: 1) Fibonacci returns the element F(0) of the Fibonacci sequence Failure/Error: expect(Fibonacci.new.element(0)). to eq 0 expected: 0 got: nil (Compared using ==) # . /spec/fibonacci_spec.Rb:5:in `block (2 levels) in <top (required)>'
– Lucas Cordeiro