Last active
August 1, 2017 21:05
-
-
Save Fohlen/9f9182f196abb09731be0e2b734e8cd1 to your computer and use it in GitHub Desktop.
Some recursive algorithms in python
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 factorial(n): | |
if n == 1: | |
return 1 | |
elif n > 1: | |
return n * factorial(n - 1) |
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 fibonacci(n): | |
""" | |
Returns the n-th element of the fibonacci sequence | |
""" | |
if n == 1: | |
return 1 | |
elif n == 2: | |
return 2 | |
elif n > 2: | |
return fibonacci(n - 1) + fibonacci(n - 2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment