Created
December 14, 2012 23:11
-
-
Save flakyfilibuster/4289481 to your computer and use it in GitHub Desktop.
just some fibonacci functions
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
#recursive | |
def fibonacci(n) | |
n <= 1 ? n : fibonacci(n-1)+fibonacci(n-2) | |
end | |
# iterative | |
def fibonacci(n) | |
c,s = 0,1 | |
n.times { c, s = s, c+s } | |
c | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment