Added self memoizing functions to chapter 4