## Problem 008

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

Don't post any spoilers
pcworx
Posts: 6
Joined: Wed Nov 27, 2013 3:52 pm

### 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

RobLewis
Posts: 2
Joined: Sun May 18, 2014 3:47 am

### 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.

TripleM
Posts: 382
Joined: Fri Sep 12, 2008 3:31 am

### Re: Problem 008

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.

euler
Posts: 3257
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."

impudens simia et macrologus profundus fabulae

RobLewis
Posts: 2
Joined: Sun May 18, 2014 3:47 am

### 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?

mdean
Posts: 165
Joined: Tue Aug 02, 2011 2:05 am

### Re: Problem 008

Might I make another suggestion? Many other problems include an example to clear up ambiguity.

euler
Posts: 3257
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

randomShort
Posts: 3
Joined: Tue May 20, 2014 9:40 pm

### Re: Problem 008

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?

hk
Posts: 10811
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

### Re: Problem 008

@RandomSort: in which programming language?

randomShort
Posts: 3
Joined: Tue May 20, 2014 9:40 pm

### Re: Problem 008

C++

hk
Posts: 10811
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

### 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.

randomShort
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.

phil88
Posts: 2
Joined: Wed May 21, 2014 9:34 pm

### 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...

rayfil
Posts: 1405
Joined: Sun Mar 26, 2006 5:30 am
Contact:

### Re: Problem 008

@phil88

Have you considered the second to last post before yours???
When you assume something, you risk being wrong half the time.

phil88
Posts: 2
Joined: Wed May 21, 2014 9:34 pm

### Re: Problem 008

D'oh... must of skipped that post. Changing from int to long long solved that one!
Thanks rayfil!

hk
Posts: 10811
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

### Re: Problem 008

phil88 wrote:D'oh... must of skipped that post. Changing from int to long long solved that one!
Thanks rayfil!
You're welcome.
hk

dan7es
Posts: 2
Joined: Thu May 22, 2014 9:15 am

### 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.

asantosbc
Posts: 1
Joined: Sun May 25, 2014 6:17 am

### 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.

TripleM
Posts: 382
Joined: Fri Sep 12, 2008 3:31 am

### 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.

SAKDOSS
Posts: 1
Joined: Fri Jul 11, 2014 11:22 pm

### Re: Problem 008

EDIT: found my mistake (int <= 2^31...)