Skip to content

Instantly share code, notes, and snippets.

@jonathanpike
Created October 16, 2015 15:38
Show Gist options
  • Save jonathanpike/3a7465fcb54ad7fef8b7 to your computer and use it in GitHub Desktop.
Save jonathanpike/3a7465fcb54ad7fef8b7 to your computer and use it in GitHub Desktop.
def recursive_fib(num)
if num <= 1
return num
else
answer = recursive_fib(num - 2) + recursive_fib(num - 1)
end
return answer.abs
end
def iterative_fib(num)
fib = [0, 1]
(num - 1).times do
nextnum = fib[-2] + fib[-1]
fib << nextnum
end
fib.last
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment