Answer ex4.31 (in progress)

This commit is only copy of ex4.29-with-memoize
Answer ex4.31 (in progress)
Answer ex4.31