Problem 292

A place to air possible concerns or difficulties in understanding ProjectEuler problems. This forum is not meant to publish solutions. This forum is NOT meant to discuss solution methods or giving hints how a problem can be solved.
Forum rules
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.

This forum is NOT meant to discuss solution methods for a problem.

In particular don't post any code fragments or results.

Don't start begging others to give partial answers to problems

Don't ask for hints how to solve a problem

Don't start a new topic for a problem if there already exists one


See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
Post Reply
sivakd
Posts: 217
Joined: Fri Jul 17, 2009 9:37 am
Location: California, USA
Contact:

Problem 292

Post 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 :).
Image
puzzle is a euphemism for lack of clarity
harryh
Posts: 2091
Joined: Tue Aug 22, 2006 9:33 pm
Location: Thessaloniki, Greece

Re: Problem 292

Post 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.
sivakd
Posts: 217
Joined: Fri Jul 17, 2009 9:37 am
Location: California, USA
Contact:

Re: Problem 292

Post 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.
Image
puzzle is a euphemism for lack of clarity
sivakd
Posts: 217
Joined: Fri Jul 17, 2009 9:37 am
Location: California, USA
Contact:

Re: Problem 292

Post 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.
Last edited by sivakd on Fri Aug 20, 2010 10:08 am, edited 1 time in total.
Image
puzzle is a euphemism for lack of clarity
User avatar
stijn263
Posts: 1505
Joined: Sat Sep 15, 2007 11:57 pm
Location: Netherlands

Re: Problem 292

Post 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!
sivakd
Posts: 217
Joined: Fri Jul 17, 2009 9:37 am
Location: California, USA
Contact:

Re: Problem 292

Post 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.
Image
puzzle is a euphemism for lack of clarity
PurplePuppy
Posts: 1
Joined: Thu Aug 19, 2010 11:56 pm

Re: Problem 292

Post 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?
Post Reply