Problem 008
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.
See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
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
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.
Re: Problem 008
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
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
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.
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
Based on your own logic that wouldn't improve the clarity in the slightest:
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.
Find the (five consecutive digits) in the 1000-digit number that have the greatest product.
as well as actually asking for the wrong thing (you need to just find the product, not the five numbers).where "five consecutive digits" could be 01234, 12345, … 56789
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.
- euler
- Administrator
- Posts: 3480
- Joined: Sun Mar 05, 2006 4:49 pm
- Location: Cheshire, England
- Contact:
Re: Problem 008
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."
"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."

impudens simia et macrologus profundus fabulae
Re: Problem 008
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?
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
Might I make another suggestion? Many other problems include an example to clear up ambiguity.

- euler
- Administrator
- Posts: 3480
- Joined: Sun Mar 05, 2006 4:49 pm
- Location: Cheshire, England
- Contact:
Re: Problem 008
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).

impudens simia et macrologus profundus fabulae
-
- Posts: 3
- Joined: Tue May 20, 2014 9:40 pm
Re: Problem 008
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?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).
Re: Problem 008
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.
The answer for 13 digits overflows int capacity (it's larger than 2^32).
Use a 64 bit container like long long or int64.

-
- Posts: 3
- Joined: Tue May 20, 2014 9:40 pm
Re: Problem 008
Yep I am using long long at the moment, still no joy.
Re: Problem 008
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...
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
@phil88
Have you considered the second to last post before yours???
Have you considered the second to last post before yours???
When you assume something, you risk being wrong half the time.
Re: Problem 008
D'oh... must of skipped that post. Changing from int to long long solved that one!
Thanks rayfil!
Thanks rayfil!
Re: Problem 008
You're welcome.phil88 wrote:D'oh... must of skipped that post. Changing from int to long long solved that one!
Thanks rayfil!
hk

Re: Problem 008
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
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
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
EDIT: found my mistake (int <= 2^31...)