I had originally coded the program wrongly. Instead of returning the Fibonacci numbers between a range (ie. startNumber 1, endNumber 20 should = only those numbers between 1
A more detailed explanation of how Memoization works for Fibonacci sequence.
# Fibonacci sequence Memoization
fib_cache = {0:0, 1:1}
def fibonacci(n):
if n < 0:
return -1
if fib_cache.has_key(n):
print "Fibonacci sequence for %d = %d cached" % (n, fib_cache[n])
return fib_cache[n]
else:
fib_cache[n] = fibonacci(n - 1) + fibonacci(n - 2)
return fib_cache[n]
if __name__ == "__main__":
print fibonacci(6)
print fib_cache
# fibonacci(7) reuses fibonacci(6) and fibonacci(5)
print fibonacci(7)
print fib_cache