Page 3 of 6

Re: Problem 008

Posted: Sat Dec 28, 2013 7:15 am
by pcworx
Hi,
Thanks for looking at my post and taking time to answer. Yes I removed all the html tags and still got syntax errors. I finally broke down and grabbed the data from someone's code who already solved the problem and posted it online. I only grabbed the code for the data though....no cheating on my part!

Thanks,
Dan

Re: Problem 008

Posted: Sun May 18, 2014 3:57 am
by RobLewis
The problem as stated is ambiguous: "Find the greatest product of five consecutive digits in the 1000-digit number."

There are (at least) two readings:

Find the (greatest product of (five consecutive digits in the 1000-digit number))

*OR*

Find the (greatest product of (five consecutive digits) in the 1000-digit number),

where "five consecutive digits" could be 01234, 12345, … 56789.

Apparently the first of these readings is what's intended, but a much clearer statement would be:

Find the five consecutive digits in the 1000-digit number that have the greatest product.

Re: Problem 008

Posted: Sun May 18, 2014 6:33 am
by TripleM
Based on your own logic that wouldn't improve the clarity in the slightest:
Find the (five consecutive digits) in the 1000-digit number that have the greatest product.
where "five consecutive digits" could be 01234, 12345, … 56789
as well as actually asking for the wrong thing (you need to just find the product, not the five numbers).

The current method is the simplest wording and the intended meaning is the most obvious one. See viewtopic.php?f=50&t=845&p=26470#p26470 for an earlier discussion on this exact point too.

Re: Problem 008

Posted: Sun May 18, 2014 11:41 am
by euler
I think, as Raymond pointed out earlier, because 167444 have already solved the problem (at the time of posting) then the wording is acceptable. However, I take the points made here and it is always our aim to ensure that the problem wording remains as unambiguous as possible there are at least two alternatives:
"Find the greatest product of five digits appearing consecutively in the 1000-digit number."
OR
"Find the greatest product of five adjacent digits in the 1000-digit number."

Re: Problem 008

Posted: Sun May 18, 2014 4:08 pm
by RobLewis
Thank you, euler, for at least acknowledging the ambiguity. I too solved it but not before spending some time puzzling over which interpretation was intended.

Unless you have a particular fetish for one-sentence statements of the problem, it seems to me the best wording would be something like this:

Find the five adjacent digits in the 1000-digit number that have the greatest product. What is this product?

Re: Problem 008

Posted: Sun May 18, 2014 7:08 pm
by mdean
Might I make another suggestion? Many other problems include an example to clear up ambiguity.

Re: Problem 008

Posted: Sun May 18, 2014 10:18 pm
by euler
I like your wording RobLewis and an example was a good suggestion, mdean. So I've combined both and changed the parameters of the problem to make it almost impossible to solve by inspection: Problem 8 (View Problem).

Re: Problem 008

Posted: Tue May 20, 2014 9:42 pm
by randomShort
euler wrote:I like your wording RobLewis and an example was a good suggestion, mdean. So I've combined both and changed the parameters of the problem to make it almost impossible to solve by inspection: Problem 8 (View Problem).
This may be my error so apologies in advance. I have wrote a script to complete Problem 8, and it works for the example with 4 adjacent numbers and for the previous edition with 5 adjacent numbers. But it just won't work with 13 no matter what I try?

Re: Problem 008

Posted: Tue May 20, 2014 9:49 pm
by hk
@RandomSort: in which programming language?

Re: Problem 008

Posted: Tue May 20, 2014 9:54 pm
by randomShort
C++

Re: Problem 008

Posted: Tue May 20, 2014 9:58 pm
by hk
I thought so.
The answer for 13 digits overflows int capacity (it's larger than 2^32).
Use a 64 bit container like long long or int64.

Re: Problem 008

Posted: Tue May 20, 2014 10:05 pm
by randomShort
Yep I am using long long at the moment, still no joy.

Re: Problem 008

Posted: Wed May 21, 2014 9:40 pm
by phil88
Hi,
First time post here...

I'm using Project Euler to practice with C++ as it's a coding language I've not used before. On my version of Problem 8, it asks me to find the greatest product of 13 adjacent digits. I've constructed a program (I won't post the code, as per rules) and I've tested it with the limit of 4 adjacent digits - sure enough it gives me the right answer. So I went ahead and set my limit to 13 (as per the question) and it's given me an answer, I put in the webpage and it's telling me it's wrong.

I did some head scratching and frantic googling - and I note that the most common version of this question is to find the greatest product of 5 adjacent digits! One page had the answer to it (I won't divulge that either) but I reset my limit in my own program to 5 and it gave me the very same answer as displayed on the webpage. So that gives me confidence that my code is indeed sound.

What I want to know is, does anyone else's page ask them to find the product of 13 adjacent digits, and if so - did they have any problems entering in the answer?

If I had been given the wrong answer for the case of 5 digits, I would have accepted a flaw in my code - but the fact I got the same answer for 4 digits and 5 digits makes me think the code is ok...

Re: Problem 008

Posted: Wed May 21, 2014 10:00 pm
by rayfil
@phil88

Have you considered the second to last post before yours???

Re: Problem 008

Posted: Wed May 21, 2014 10:11 pm
by phil88
D'oh... must of skipped that post. Changing from int to long long solved that one!
Thanks rayfil!

Re: Problem 008

Posted: Thu May 22, 2014 9:18 am
by hk
phil88 wrote:D'oh... must of skipped that post. Changing from int to long long solved that one!
Thanks rayfil!
You're welcome.
hk

Re: Problem 008

Posted: Thu May 22, 2014 9:41 am
by dan7es
Also, make sure you are using the digits only. I forgot to remove some new lines from a multi-line string. The confusing part was that I got the right answers with 4 and 5 digits regardless.

Re: Problem 008

Posted: Sun May 25, 2014 6:21 am
by asantosbc
Could you please verify problem 8? It reads: "The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832". However, 5832 is not in the 1000 digit number.

Re: Problem 008

Posted: Sun May 25, 2014 6:38 am
by TripleM
The four adjacent digits in the 1000-digit number are 9, 9, 8, 9. Their product doesn't have to be in the 1000-digit number.

Re: Problem 008

Posted: Fri Jul 11, 2014 11:32 pm
by SAKDOSS
EDIT: found my mistake (int <= 2^31...)