I have a recursion function defined as follows:
def myfunc(n, d):
if n in d:
return d[n]
else:
return myfunc(n-1,d) + myfunc(n-2,d)
and if I run it with the following parameters:
myfunc(6, {1:1,2:2})
I get this 13, but I expected the sum to be 8? Since the recursion would look something like this:
myfunc(5,d) + myfunc(4,d)
myfunc(4,d) + 2
myfunc(3,d) + 2
2 + 2
which equals = 2 + 2 + 2 + 2 = 8? Could someone explain? Thank you!