memoized numberOfWays