Page 1 of 1

Problem 292

Posted: Thu Jul 08, 2010 3:43 am
by sivakd
Hi, I finally have a solution that is valid for P(30) and P(60). The problem now is that it is very slow (crossing 1 minute limit for P(80). Before I embark on further optimization or a different strategy, I am curious on what is the typical runtime people submitted? I am sure there has to be one solution that takes less than 18 minutes 44 seconds :).

Re: Problem 292

Posted: Thu Jul 08, 2010 6:53 am
by harryh
The fastest solutions are 0.1 sec to a few seconds. There are many solutions approx. 12 sec - 50 sec and a few that run for considerably more than 1 min.

Re: Problem 292

Posted: Thu Jul 08, 2010 8:54 am
by sivakd
Thanks harry. With memoization the time reduces to 1.5 seconds but the answer is wrong :). I don't know what to make of it because P(30) and P(60) are still correct. May be this is one of those problems where with larger n, the algorithm has some bugs? I need to figure that out.

Re: Problem 292

Posted: Thu Jul 08, 2010 9:16 am
by sivakd
Ok, finally done. Still 1.5 seconds. I had one premature optimization that's throwing the value off for higher n. I removed it and got the right answer. It would be very hard to figure out what was wrong with that optimization. I won't sweat on it though.

Re: Problem 292

Posted: Thu Jul 08, 2010 9:17 am
by stijn263
p(120) is larger than 231 so you might have an overflow problem?

Good luck!

edit: I see you already got it. Good job!

Re: Problem 292

Posted: Fri Jul 09, 2010 7:38 am
by sivakd
Thanks stijn263. I couldn't resist to figure out what the issue was. It is not related to overflow. It turned out that the primitive pythagorean triplets don't get generated in increasing order of hypotenuse. Just a bad assumption. So the issue actually kicked in for P(83). Hopefully I am not giving away too much info.

Re: Problem 292

Posted: Fri Aug 20, 2010 2:07 am
by PurplePuppy
My solution to problem 292 runs too slowly!
My 6-layer nest of for loops have already caused it to take around 3 minutes for P(60). Maybe I should learn some memoization. Do the solutions of everyone make use of memoization for this problem?