<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">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">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>