import Data.Array import Data.Word import Data.List collatz_array = let upperbound = 1000000 a = array (1, upperbound) [(i :: Word64, f i :: Int) | i <- [1..upperbound]] f i = i `seq` let check_f i = i `seq` if i <= upperbound then a ! i else f i in if (i == 1) then 0 else (check_f ((if (even i) then i else 3 * i + 1) `div` 2)) + 1 in a main = putStrLn $ show $ foldl1' (\(x1,x2) (y1,y2) -> if (x2 >= y2) then (x1, x2) else (y1, y2)) $! (assocs collatz_array)