Last active
July 10, 2022 13:54
-
-
Save bennett39/4fdf872f941267ce8e5f3f998747af22 to your computer and use it in GitHub Desktop.
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): | |
"""Calculate the Nth fibonacci number. | |
Intentionally don't use dynamic programming. Goal is to simulate a long-running task. | |
""" | |
if n < 0: | |
raise ValueError('Negative numbers are not supported') | |
elif n == 0: | |
return 0 | |
elif n <= 2: | |
return 1 | |
return fib(n - 2) + fib(n - 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment