memoization, finished chapter 4