The memoized version wasn't dying, but it would error out with a "Cant' grow hashtable" error when it hit 1.5M/3M entries (attempting to grow it to 6M entries).

My completely iterative, bruteforce, non-memoized version is the one dying:

Code: Select all

`(loop for x from 1 to 999999`

with long-chain-steps = 0

with long-chain-num = 1

for steps = (collatz x)

if (> steps long-chain-steps)

do (setf long-chain-steps steps long-chain-num x)

finally (return (list long-chain-steps long-chain-num)))

(defun collatz (n)

(loop for x = n then (if (evenp x) (/ x 2) (1+ (* 3 x)))

for steps upfrom 1

until (= x 1)

finally (return steps)))

I have no clue why. Like I said, I was able to find the answer by just running it with small enough increments (100k works for most increments, with 50k for the few that still die), but the problem is very annoying. There's not even any consing! I'll probably take it the Corman forums and ask if they know anything.