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] |
p14_fasm 3.58s
p14_viac 0.84s
(same result with foldl'
-- guess the strictness analyser does a good job for this one.)
great thanks a lot for this.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should probably use
foldl'
instead offoldl
. Import it fromData.List
.