Skip to content

Instantly share code, notes, and snippets.

@craigjbass
Last active December 30, 2015 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigjbass/7816405 to your computer and use it in GitHub Desktop.
Save craigjbass/7816405 to your computer and use it in GitHub Desktop.
Longest Collatz sequence (Problem 14) http://projecteuler.net/problem=14
module Main (
main
) where
import Data.List (maximumBy)
import Data.Function (on)
collatz 1 = [1]
collatz i = i : (if odd i then collatz $ 3*i + 1 else collatz $ i `div` 2)
main = putStrLn $ show $ maximumBy (compare `on` length) $ map collatz [1..1000000]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment