Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Assignment from the Odin Project
def fibs(num)
if num == 0
return 0
else
sequence = [0,1];
for i in 1...num
fibby = sequence[i] + sequence[i-1]
sequence.push(fibby)
end
return sequence.last
end
end #End of fibs
def fibs_rec(num, sequence=[0,1], counter=2)
if num == 0
return 0
elsif num == 1
return 1
else
sequence.push( sequence[counter-1] + sequence[counter-2] )
counter += 1
fibs_rec(num - 1, sequence, counter)
end
return sequence.last
end #End of fibs_rec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment