Created
October 16, 2015 15:38
-
-
Save jonathanpike/3a7465fcb54ad7fef8b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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