Skip to content

Instantly share code, notes, and snippets.

@raeq
Created September 5, 2020 09:54
Show Gist options
  • Save raeq/239c063e7d05e03f3ca97cdc97776f9b to your computer and use it in GitHub Desktop.
Save raeq/239c063e7d05e03f3ca97cdc97776f9b to your computer and use it in GitHub Desktop.
Recursive method to find fibonacci numbers
def fibonacci_recursive(i: int = None) -> int:
"""
The simplest way to calculate a fibonacci number, using recursion.
Simple works, but not in all cases!
>>> fibonacci_recursive(20)
6765
>>> # fibonacci_recursive(100) No, don't do this, it will take forever and exhaust your computer's memory
"""
if i == 0:
return 0
if i == 1:
return 1
return fibonacci_recursive(i - 1) + fibonacci_recursive(i - 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment