<div dir="ltr">Take a look here: <a href="https://www.haskell.org/haskellwiki/Foldr_Foldl_Foldl">https://www.haskell.org/haskellwiki/Foldr_Foldl_Foldl</a>'<div><br></div><div>Foldr is not recommended in most cases, the above article explains it all.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 18 April 2015 at 09:11, Sourabh <span dir="ltr"><<a href="mailto:sourabh.s.joshi@gmail.com" target="_blank">sourabh.s.joshi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">So I decided to try the Google Code Jam this year, and decided to code in Haskell. <div><br></div><div>I passed the qualifiers, and today was Round 1A. I managed to get the first problem right (both small and large input), and got the 2nd problem right (for the small input). However, for the large input, it ran out of stack space with the following error:</div><div>Stack space overflow: current size 33632 bytes</div><div>Use '+RTS -Ksize -RTS' to increase it. </div><div><br></div><div>Can someone tell me how I could have avoided or fixed this? </div><div><br></div><div>It is also very possible that I had an algorithmic issue (needed to optimize my code or have a different algorithm for the large input perhaps?). </div><div><br></div><div>Here is the problem description:</div><div><a href="https://code.google.com/codejam/contest/4224486/dashboard#s=p1" target="_blank">https://code.google.com/codejam/contest/4224486/dashboard#s=p1</a> <br></div><div><br></div><div>And here is my code:</div><div><a href="https://github.com/cbrghostrider/Hacking/blob/master/codeJam/2015/haircut/haircut_try2.hs" target="_blank">https://github.com/cbrghostrider/Hacking/blob/master/codeJam/2015/haircut/haircut_try2.hs</a> <br></div><div><br></div><div>I made sure to use foldr, which is supposedly more stack efficient I believe. I don't know if the list append (++) was causing issues.</div><div><br></div><div>If anyone can spot any problems, or provide suggestions, I would really appreciate it! Even though the round is done, I'd like to optimize this to make it run within 8 minutes, as intended.</div><div><br></div><div>Thanks in advance!</div><div>--</div><div>SSJ</div></div>
<br>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Regards</div><div dir="ltr"><div><br></div><div>Sumit Sahrawat</div></div></div></div></div></div></div>
</div>