-- Problems/Problem014.hs
module Problems.Problem014 (p14) where

import Data.List
import Helpers.Numbers

main = print p14

p14 :: Int
p14 = snd $ foldl1' max $ map (\x -> ((length $ collatz x),x)) [500001,500003..999999]

collatzList :: Int -> [(Int,Int)]
collatzList num 
    | num == 1 = [(1,1)]
    | otherwise = (num,(snd $ head $ colList) + 1) : colList
    where
        colList = if even num
            then collatzList (num `div` 2)
            else collatzList (3 * num + 1)

nextCollatz :: Int -> Int
nextCollatz num
    | odd num = 3 * num + 1
    | otherwise = num `div` 2
