Created
October 22, 2015 20:24
-
-
Save gagaception/6ee130fe568cf0ec9144 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(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