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


See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
pcworx
Posts: 6
Joined: Wed Nov 27, 2013 3:52 pm

Re: Problem 008

Post by pcworx » Sat Dec 28, 2013 7:15 am

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 2:47 am

Re: Problem 008

Post by RobLewis » Sun May 18, 2014 2:57 am

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 2:31 am

Re: Problem 008

Post by TripleM » Sun May 18, 2014 5:33 am

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.

User avatar
euler
Administrator
Posts: 3069
Joined: Sun Mar 05, 2006 4:49 pm
Location: Cheshire, England
Contact:

Re: Problem 008

Post by euler » Sun May 18, 2014 10:41 am

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."
Image
impudens simia et macrologus profundus fabulae

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

Re: Problem 008

Post by RobLewis » Sun May 18, 2014 3:08 pm

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: 143
Joined: Tue Aug 02, 2011 1:05 am

Re: Problem 008

Post by mdean » Sun May 18, 2014 6:08 pm

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

User avatar
euler
Administrator
Posts: 3069
Joined: Sun Mar 05, 2006 4:49 pm
Location: Cheshire, England
Contact:

Re: Problem 008

Post by euler » Sun May 18, 2014 9:18 pm

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).
Image
impudens simia et macrologus profundus fabulae

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

Re: Problem 008

Post by randomShort » Tue May 20, 2014 8:42 pm

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?

User avatar
hk
Administrator
Posts: 10422
Joined: Sun Mar 26, 2006 9:34 am
Location: Haren, Netherlands

Re: Problem 008

Post by hk » Tue May 20, 2014 8:49 pm

@RandomSort: in which programming language?
Image

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

Re: Problem 008

Post by randomShort » Tue May 20, 2014 8:54 pm

C++

User avatar
hk
Administrator
Posts: 10422
Joined: Sun Mar 26, 2006 9:34 am
Location: Haren, Netherlands

Re: Problem 008

Post by hk » Tue May 20, 2014 8:58 pm

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

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

Re: Problem 008

Post by randomShort » Tue May 20, 2014 9:05 pm

Yep I am using long long at the moment, still no joy.

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

Re: Problem 008

Post by phil88 » Wed May 21, 2014 8:40 pm

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

User avatar
rayfil
Administrator
Posts: 1401
Joined: Sun Mar 26, 2006 4:30 am
Location: Ontario, Canada
Contact:

Re: Problem 008

Post by rayfil » Wed May 21, 2014 9:00 pm

@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 8:34 pm

Re: Problem 008

Post by phil88 » Wed May 21, 2014 9:11 pm

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

User avatar
hk
Administrator
Posts: 10422
Joined: Sun Mar 26, 2006 9:34 am
Location: Haren, Netherlands

Re: Problem 008

Post by hk » Thu May 22, 2014 8:18 am

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

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

Re: Problem 008

Post by dan7es » Thu May 22, 2014 8:41 am

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 5:17 am

Re: Problem 008

Post by asantosbc » Sun May 25, 2014 5:21 am

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 2:31 am

Re: Problem 008

Post by TripleM » Sun May 25, 2014 5:38 am

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 10:22 pm

Re: Problem 008

Post by SAKDOSS » Fri Jul 11, 2014 10:32 pm

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

Post Reply