Nov 24
Questions about anything?
Any project topics you'd care to talk about?
Last we started to discuss a number of
recursion examples
including searching in a list, searching
a game move tree (the trickiest), finding the maximum number
in a list, and base conversion.
We'll work through several of these in class.
Please do continue to work on your projects.
(If you haven't started one yet, please do
pick one and start "real soon".)
First we talked about game search, and went over
my subtraction game program.
Then we did a bit with memoization :
memo = {} # remember values of fib(x)
def fib(x):
if not memo.has_key(x):
print " calculating fib({})".format(x)
if x < 2:
memo[x] = 1
else:
memo[x] = fib(x-1) + fib(x-2)
return memo[x]
Without the memo dict, calculating (say) fib(100)
takes longer than you'd want to wait, since
does the same calculation many times
along the way.