Page 3 of 4

Re: Problem 044

Posted: Sat Aug 06, 2011 6:11 am
by frogjg2003
I saw that a lot of people said that simply finding the first pair is the correct answer, so I created a code that does that, took 5 1/2 seconds. I then spent a few days trying to come up with a code that proves it's the minimal solution. I'm pretty sure I have it (gives the right answer) but it takes about an hour to run. Can some of you look at my code and give me some optimization tips? I really don't want to move on to the next problem until I completely understand this one.

EDIT: If the optimization is to find the first pair, and then just test all pairs less than that, then I haven't tried that yet, but I'll probably tomorrow.

Re: Problem 044

Posted: Tue Aug 09, 2011 5:18 pm
by thundre
frogjg2003 wrote:Can some of you look at my code and give me some optimization tips?
After you enter the correct answer, you can go to http://projecteuler.net/index.php?section=forum&id=44 to see dozens of example programs that solve it quickly. Since those perform better than yours, the burden of reading code and comparing algorithms should be on you.

Re: Problem 044

Posted: Wed Sep 28, 2011 11:24 pm
by JMW1994
Find the pair of pentagonal numbers, Pj and Pk, for which their sum and difference is pentagonal and D = |Pk Pj| is minimised; what is the value of D?
Does the problem mean to take the two pentagonal numbers that you're adding and subtracting to or does it mean to take the result of Pj from the sum of the two pentagonal numbers and the result of Pk of the difference of two pentagonal numbers and subtract it from there and take the absolute value of it? If I'm wrong on either, can you tell exactly what the problem is asking for?

Thanks.

Re: Problem 044

Posted: Thu Sep 29, 2011 2:30 am
by PurpleBlu3s
JMW1994 wrote:
Find the pair of pentagonal numbers, Pj and Pk, for which their sum and difference is pentagonal and D = |Pk Pj| is minimised; what is the value of D?
Does the problem mean to take the two pentagonal numbers that you're adding and subtracting to or does it mean to take the result of Pj from the sum of the two pentagonal numbers and the result of Pk of the difference of two pentagonal numbers and subtract it from there and take the absolute value of it? If I'm wrong on either, can you tell exactly what the problem is asking for?

Thanks.
The difference of the two pentagonal numbers is what you should submit.

Re: Problem 044

Posted: Thu Sep 29, 2011 3:01 am
by JMW1994
The difference of the two pentagonal numbers is what you should submit.
You don't take the sum and difference and then subtracting those value? For example, you don't mean this: (1247+715)-(1247-715), but rather: (1247-715) as long as the pentagonal numbers add up to another pentagonal number and the subtraction of the pentagonal numbers subtract to another pentagonal number? In addition, the result is supposed to be in the millions because 1) everyone tends to hit that and 2) I'm hitting the result only in a thousand, correct?

I'm only asking to verify.

Re: Problem 044

Posted: Thu Sep 29, 2011 10:07 am
by Francky
thundre wrote:
frogjg2003 wrote:Can some of you look at my code and give me some optimization tips?
After you enter the correct answer, you can go to http://projecteuler.net/index.php?section=forum&id=44 to see dozens of example programs that solve it quickly. Since those perform better than yours, the burden of reading code and comparing algorithms should be on you.
frogjg2003 is right, none in the first pages of the forum thread proove that D is the minimum !!!
It's a coincidence that the answer is correct for all those submissions.

I propose page 5 of this thread, a correct solution that proove D is THE minimum, in less than a second, the second solution is 3215928562 (much longer time machine).
I never wrote a math paper in english, so if someone could help me to translate it in a correct english, it would be kind for all non-french readers. Thanks.

--
I think the problem has been modified in the early times, and in the begining it wasn't ask for D minimum, but now it is ! (Euler said, it's a much much harder problem, but with the same answer).

Re: Problem 044

Posted: Thu Sep 29, 2011 11:20 am
by PurpleBlu3s
JMW1994 wrote:
The difference of the two pentagonal numbers is what you should submit.
You don't take the sum and difference and then subtracting those value? For example, you don't mean this: (1247+715)-(1247-715), but rather: (1247-715) as long as the pentagonal numbers add up to another pentagonal number and the subtraction of the pentagonal numbers subtract to another pentagonal number? In addition, the result is supposed to be in the millions because 1) everyone tends to hit that and 2) I'm hitting the result only in a thousand, correct?

I'm only asking to verify.
You have to find two pentagonal numbers, Pj and Pk, such that their sum and their difference are both pentagonal numbers as well. So if you look at the example of P4 and P7, 22 and 70, imagine that their difference was in fact pentagonal, then you would submit as your answer, 70 - 22 = 48.

Re: Problem 044

Posted: Fri Oct 28, 2011 12:51 am
by JMW1994
It appears that these weren't answered.
In addition, the result is supposed to be in the millions because 1) everyone tends to hit that and 2) I'm hitting the result only in a thousand, correct?
Thanks.

Re: Problem 044

Posted: Fri Oct 28, 2011 1:53 am
by TripleM
I'm not sure what you mean by you're hitting the result in the thousands, but if you have come up with an answer and it isn't being accepted, then it won't be the correct answer. There's no limit on how large the correct answer is.

Re: Problem 044

Posted: Wed Mar 12, 2014 4:46 pm
by monkey68pl
Hello everyone. I've been stuck with this problem for couple of days, and I'm wondering if I'm doing it correctly. Now, my solution takes a lot of time (for now, about 36 hours and still searching for solution) - and I'm not sure that I wrote it correctly, since I cannot check it as other problems (where answers for 'small probems' are given). Is anyone willing to recieve a PM from me, and tell me if I'm doing it correctly? I don't know if you allow it - but some hint about upper bound for which I should calculate would be great.

For me - the most difficult problem so far, due to my complete lack of ideas how to optimize my algorithm.

Best regards,

K.

Re: Problem 044

Posted: Wed Mar 12, 2014 6:14 pm
by Svartskägg
monkey68pl wrote:Now, my solution takes a lot of time (for now, about 36 hours and still searching for solution)
My solution takes 35 milliseconds, so you are obviously not doing it correctly.

Re: Problem 044

Posted: Wed Mar 12, 2014 8:15 pm
by nicolas.patrois
Mine takes a few seconds but my processors are already busy.

Re: Problem 044

Posted: Wed Mar 12, 2014 9:42 pm
by monkey68pl
I know that I'm wrong, yet I think that I used correct method. This means that I have some huge mistake in my program (which is possible, since I'm not programmer, at least in Python) or my method is completely wrong - but I can't think of anything better. I think that I'll find solution, and then I'll check how other people solved this - but this is similiar to just looking up the answer in google, which I want to avoid. So I thought that maybe someone can guide me to correct solution.

Is there any information about pentagonal numbers that would help me? I looked in the net, did some calculations on paper, but I havent found anything useful for this problem.

Re: Problem 044

Posted: Wed Mar 12, 2014 11:42 pm
by TripleM
If you want to PM me your program, plus a description of what it does and why you think this should solve the problem, I can try to help.

Re: Problem 044

Posted: Sat Mar 21, 2015 4:09 am
by solarmew
sooooooo........ negative "n" don't count then?

Re: Problem 044

Posted: Sat Mar 21, 2015 4:17 am
by Georg
n has to be a natural Number.

Problem 044

Posted: Sun Feb 14, 2016 5:20 pm
by Math_Max
Hi everybody,

I was solving problem 44 just now, and again I came across this issue which I don't really understand how to approach.

Here's the problem:
Pentagonal numbers are generated by the formula, Pn=n(3n−1)/2. The first ten pentagonal numbers are:

1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...

It can be seen that P4 + P7 = 22 + 70 = 92 = P8. However, their difference, 70 − 22 = 48, is not pentagonal.

Find the pair of pentagonal numbers, Pj and Pk, for which their sum and difference are pentagonal and D = |Pk − Pj| is minimised; what is the value of D?


I approach the problem the brute-force way which I think works for most of the problems on page1. So I made some for loops, but what I don't understand is this. How do you know at what number you can stop looking. For instance how do you know that there doesn't exist a pair of Pentagonal numbers with a million digits which would be the answer. Obviously, this would take infinite time to calculate, but how would you know?

Re: How to determine the upper limit of your search?

Posted: Sun Feb 14, 2016 5:53 pm
by mpiotte
Math_Max wrote:...I approach the problem the brute-force way which I think works for most of the problems on page1. So I made some for loops, but what I don't understand is this. How do you know at what number you can stop looking. For instance how do you know that there doesn't exist a pair of Pentagonal numbers with a million digits which would be the answer. Obviously, this would take infinite time to calculate, but how would you know?
Let's assume you found a pair (Pj, Pk) of pentagonal numbers that satisfy the problem statement.
Look at the difference between consecutive pentagonal numbers Pn+1 - Pn. As n grows larger, so does Pn+1 - Pn. There must be a value of n for which Pn+1 - Pn ≥ |Pj - Pk|. Thus, if there is a pair of pentagonal numbers with a smaller difference, it must occur at or before Pn, and Pn is an upper bound of the search space. This proves the search space is not infinite.

Re: How to determine the upper limit of your search?

Posted: Sun Feb 14, 2016 6:58 pm
by Math_Max
mpiotte wrote: Let's assume you found a pair (Pj, Pk) of pentagonal numbers that satisfy the problem statement.
Look at the difference between consecutive pentagonal numbers Pn+1 - Pn. As n grows larger, so does Pn+1 - Pn. There must be a value of n for which Pn+1 - Pn ≥ |Pj - Pk|. Thus, if there is a pair of pentagonal numbers with a smaller difference, it must occur at or before Pn, and Pn is an upper bound of the search space. This proves the search space is not infinite.
Thanks dude, had to think for a minute but I understand it now :D. So in a sense you have add something to your program that limits the search space everytime you find a solution?

Re: Problem 044

Posted: Sun Feb 14, 2016 8:44 pm
by hk
Moved to the relevant forum and topic.