removed something

This commit is contained in:
booboy 2018-01-12 10:14:16 -06:00
parent 9ee07824cf
commit a4b08f3b6d
2 changed files with 0 additions and 43 deletions

View file

@ -1,16 +0,0 @@
#!/usr/bin/env python3
# this shows the fibonacci sequence with basic recursion.
# note that it gets very slow at the end due to the recursion
def fibonacci(n):
if n == 1:
return 1
elif n == 2:
return 1
elif n > 2:
return fibonacci(n-1) + fibonacci(n-2)
for n in range(1, 101):
print(n, ":", fibonacci(n))

View file

@ -1,27 +0,0 @@
#!/usr/bin/env python3
# this introduces recursive fibonacci with a cache of recent function calls
# this is introducing memoization: caching recent function call results
fibonacci_cache = {}
def fibonacci(n):
# If we have cached the value, then return it
if n in fibonacci_cache:
return fibonacci_cache[n]
# compute nth term
if n == 1:
value = 1
elif n == 2:
value = 1
elif n > 2:
value = fibonacci(n-1) + fibonacci(n-2)
fibonacci_cache[n] = value
return value
for n in range(1, 101):
print(n, ":", fibonacci(n))