[Haskell-beginners] GCJ 2015 - Round 1A Problem - Haircut

Sourabh sourabh.s.joshi at gmail.com
Sat Apr 18 03:41:41 UTC 2015


So I decided to try the Google Code Jam this year, and decided to code in
Haskell.

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:
Stack space overflow: current size 33632 bytes
Use '+RTS -Ksize -RTS' to increase it.

Can someone tell me how I could have avoided or fixed this?

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?).

Here is the problem description:
https://code.google.com/codejam/contest/4224486/dashboard#s=p1

And here is my code:
https://github.com/cbrghostrider/Hacking/blob/master/codeJam/2015/haircut/haircut_try2.hs


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.

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.

Thanks in advance!
--
SSJ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150417/a07ec699/attachment.html>


More information about the Beginners mailing list