Last active
December 16, 2019 01:38
-
-
Save FerdinaKusumah/aa88bd4ff7e50d64d3ef268e0ebc666c to your computer and use it in GitHub Desktop.
Fibonacci
This file contains hidden or 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: int): | |
""" Define function fibonacci with recursion""" | |
if n == 0: | |
return 0 | |
elif n == 1: | |
return 1 | |
return fibonacci(n-1) + fibonacci(n-2) | |
N = 35 | |
fib = fibonacci(N) | |
print(timeit.timeit("fibonacci(N)", globals=globals(), number=1)) | |
# Running for 7.011678666000001 seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment