Skip to content

Instantly share code, notes, and snippets.

@dterei
Created May 1, 2010 08:58
Show Gist options
  • Save dterei/386166 to your computer and use it in GitHub Desktop.
Save dterei/386166 to your computer and use it in GitHub Desktop.
Euler Problem 14
import Data.Word
collatzLen :: Int -> Word32 -> Int
collatzLen c 1 = c
collatzLen c n = collatzLen (c+1) $ if n `mod` 2 == 0 then n `div` 2 else 3*n+1
pmax x n = x `max` (collatzLen 1 n, n)
main = print . solve $ 1000000
where solve xs = foldl pmax (1,1) [2..xs-1]
@dterei
Copy link
Author

dterei commented May 1, 2010

great thanks a lot for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment