collatz sequence with memoization to speed it up