Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import time
- def fib0(n):
- if n > 1:
- return fib0(n - 1) + fib0(n - 2)
- if n == 1:
- return 1
- if n == 0:
- return 0
- def fib1(n):
- if n > 2:
- return 2 * fib1(n - 2) + fib1(n - 3)
- if n == 1 or n == 2:
- return 1
- if n == 0:
- return 0
- if __name__ == "__main__":
- a = 40
- start = time.time()
- f = fib0(a)
- stop = time.time()
- print(f, stop - start)
- start = time.time()
- f = fib1(a)
- stop = time.time()
- print(f, stop - start)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement