Created
November 28, 2008 22:49
-
-
Save jbgutierrez/30122 to your computer and use it in GitHub Desktop.
Smart definition of Fibonacci Sequence (http://tinyurl.com/dst6f)
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 fib n | |
case n | |
when 0..1 then n | |
else fib(n-1) + fib(n-2) | |
end | |
end | |
# thouth it should be rewritten as a loop to avoid a stackoverflow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment