add problem 077
generalize function and enabled @memoize