added memoization sample code
Used memoization to shave about half an hour off mathcalG runtime