
28 Jul
2008
28 Jul
'08
7:53 p.m.
Since this is the "beginners" list, could someone explain me why using g
made everything run like the wind, with almost no memory?
I am puzzled! :-(
On Mon, Jul 28, 2008 at 17:32, Steve Klabnik
Finally, what I ended up doing:
f :: Integer -> Integer -> Integer f acc x | x == 1 = acc | even x = f (acc + 1) (x `div` 2) | otherwise = f (acc + 1) (3 * x + 1)
g :: Integer -> (Integer, Integer) g x = (f 1 x, x)
answer = (foldl' max (0,0)) $ map g [1 .. 999999]
main = putStrLn( show answer)
-- Rafael Gustavo da Cunha Pereira Pinto Electronic Engineer, MSc.