Project Euler Problem 014
import Data.Array import Data.Array.ST import Control.Monad.ST n :: Integer n = 10^(6::Integer)-1 sol1 :: Array Integer Integer sol1 = a where a = runSTArray $ do ar <- (newListArray (1,n) (1:[col x | x<-[2..n]])) :: ST s (STArray s Integer Integer) return ar col x | even x = if r<=n then 1+a!r else 1 + col r where r = x`quot`2 col x = if r<=n then 1+a!r else 1 + col r where r = 3*x+1 -- (525,837799) ans1 :: (Integer, Integer) ans1 = maximum $ zip (elems sol1) [1..] -- 837799 main :: IO () main = print $ snd ans1