Skip to content

Instantly share code, notes, and snippets.

@Fohlen
Last active August 1, 2017 21:05
Show Gist options
  • Save Fohlen/9f9182f196abb09731be0e2b734e8cd1 to your computer and use it in GitHub Desktop.
Save Fohlen/9f9182f196abb09731be0e2b734e8cd1 to your computer and use it in GitHub Desktop.
Some recursive algorithms in python
def factorial(n):
if n == 1:
return 1
elif n > 1:
return n * factorial(n - 1)
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