Skip to content

Instantly share code, notes, and snippets.

@alexcrist
Created January 14, 2020 23:49
Show Gist options
  • Save alexcrist/5e16341eba1d5bc41a10c0ea541a5e1a to your computer and use it in GitHub Desktop.
Save alexcrist/5e16341eba1d5bc41a10c0ea541a5e1a to your computer and use it in GitHub Desktop.
# Returns the nth iteration of the fibonacci sequence
# n: 0 1 2 3 4 5 6
# output: 1 1 2 3 5 8 13
def fibonacci(n):
# Base case
if n == 0 or n == 1:
return 1
# Recursive case
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