Skip to content

Instantly share code, notes, and snippets.

@oskimura
Created September 30, 2010 04:02
Show Gist options
  • Save oskimura/603996 to your computer and use it in GitHub Desktop.
Save oskimura/603996 to your computer and use it in GitHub Desktop.
module Main where
euler14 = max' [(length xs, n) | n<-[1..1000000], let xs = (collatz n)]
where
comp x y = if (fst x) > (fst y) then x else y
max' = (foldr comp (0,0))
collatz n
| n==1 = [1]
| even n = let m = n `div` 2 in n:(collatz m)
| otherwise = let m = 3*n+1 in n:(collatz m)
main = print $ euler14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment