Skip to content

Instantly share code, notes, and snippets.

@rhysd
Created August 5, 2012 16:20
Show Gist options
  • Save rhysd/3265670 to your computer and use it in GitHub Desktop.
Save rhysd/3265670 to your computer and use it in GitHub Desktop.
import Data.List (maximumBy)
import Data.Function (on)
collatzLength :: Int -> Int
collatzLength 1 = 1
collatzLength n
| even n = 1 + collatzLength(n `div` 2)
| odd n = 1 + collatzLength(3*n + 1)
main = print $ maximumBy (compare `on` collatzLength) [1..1000000]
-- 837799
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment