First naive attempt at challenge 6
Improved solution for challenge 6 by use of memoization