Created
May 1, 2010 08:58
-
-
Save dterei/386166 to your computer and use it in GitHub Desktop.
Euler Problem 14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great thanks a lot for this.