<div dir="ltr"><br><div class="gmail_quote">On Mon, Jul 28, 2008 at 12:15 PM, Niels Aan de Brugh <span dir="ltr">&lt;<a href="mailto:nielsadb@gmail.com" target="_blank">nielsadb@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div><br></div>
Because you&#39;re not providing the right number. :-)<div></div></blockquote><div><br>You know, I realized that this morning after I woke up....ha ha. Sometimes a good night&#39;s sleep is all it takes...<br>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


I&#39;ve tested your code with strictness annotations and it appears to not make a difference. GHC employs several optimization techniques, one of those being strictness analysis, so maybe it is already using a strict, unboxed integer.<br>


</blockquote><div><br>Ah. I figured that I probably didn&#39;t have to worry about it manually...<br>&nbsp;</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br>
The real speed-up (a non-linear one) here is not to re-calculate every sequence over and over again, but keep it in a map/array (as suggested by Rafael and me). I&#39;ve found some Euler puzzles are impossible to solve without this technique.<br>

<font color="#888888">
<br>
Niels<br>
</font><br>
P.S.: If you&#39;re really going for speed, compile (not interpret) the code (using -O -fvia-C, and there&#39;s some more stuff in the manual) using the latest greatest version of GHC.<br>
</blockquote></div><br><br>I&#39;ll keep this in mind. Right now I&#39;m going for just doing it, but I&#39;ll heed your advice for future problems.<br><br><br><br>Finally, what I ended up doing:<br><br><blockquote>f :: Integer -&gt; Integer -&gt; Integer <br>
f acc x <br>&nbsp;&nbsp;&nbsp; | x == 1 = acc <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | even x = f (acc + 1) (x `div` 2) <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; | otherwise = f (acc + 1) (3 * x + 1)<br><br>g :: Integer -&gt; (Integer, Integer)<br>g x = (f 1 x, x)<br><br>answer = (foldl&#39; max (0,0)) $ map g [1 .. 999999]<br>
<br><br>main = putStrLn( show answer)<br></blockquote><br>Again, not the most efficient, but pretty clean. Runs in just under a minute on my machine. Thanks again!<br></div>