Created
February 9, 2013 08:55
-
-
Save passcod/4744632 to your computer and use it in GitHub Desktop.
Fibonacci bench
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
function fib(n) { | |
return n < 2 ? n : fib(n-1) + fib(n-2); | |
} | |
print(fib(35)); |
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
# Python 2 | |
def fib(n): | |
if (n < 2): | |
return n | |
else: | |
return fib(n-1) + fib(n-2) | |
print fib(35) |
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 | |
if n < 2 | |
n | |
else | |
fib(n-1) + fib(n-2) | |
end | |
end | |
puts fib 35 |
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
# Python 3 | |
def fib(n): | |
if (n < 2): | |
return n | |
else: | |
return fib(n-1) + fib(n-2) | |
print(fib(35)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment