Skip to content

Instantly share code, notes, and snippets.

@gagaception
Created October 22, 2015 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gagaception/6ee130fe568cf0ec9144 to your computer and use it in GitHub Desktop.
Save gagaception/6ee130fe568cf0ec9144 to your computer and use it in GitHub Desktop.
def recursive_fib(n)
if n <= 1
return n
else
result = recursive_fib(n-2) + recursive_fib(n-1)
end
end
def itterative_fib(n)
fib = [0, 1]
(n-1).times do
next_n = fib[-1] + fib [-2]
fib << next_n
end
fib.last
end
puts recursive_fib(10)
puts itterative_fib(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment