Problem 006

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.
ABC_TheCMan
Posts: 1
Joined: Sun Jul 26, 2009 8:58 pm

Problem 006

Post by ABC_TheCMan »

Hi,

the problems ask for
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
But is should be:
Find the difference between the square of the sum of the first one hundred natural numbers and the sum of the squares?

Did anybody hit the same problem?

ABC_TheCMan
User avatar
daniel.is.fischer
Posts: 2400
Joined: Sun Sep 02, 2007 11:15 pm
Location: Bremen, Germany

Re: Problem 6 - Wrong question?

Post by daniel.is.fischer »

Fortunately, the example makes it clear that the desired answer is the absolute difference.
But yes, that irritated me, too.
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
userProjectEuler
Posts: 7
Joined: Sat Jul 25, 2009 8:52 pm

Problem 006 error

Post by userProjectEuler »

the problem is asking:
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
which results in a negative value.
the problem should be reformulated to:
Find the difference between the square of the sum of the first one hundred natural numbers and the sum of the squares.

right?!!
genious999
Posts: 53
Joined: Mon Oct 20, 2008 10:48 pm

Re: Problem 6 error

Post by genious999 »

"Difference" in that context means find the absolute difference
see here:
viewtopic.php?f=50&t=1614
userProjectEuler
Posts: 7
Joined: Sat Jul 25, 2009 8:52 pm

Re: Problem 6 error

Post by userProjectEuler »

I didn't understand why in that context it means absolute difference. :/
quilan
Posts: 182
Joined: Fri Aug 03, 2007 11:08 pm

Re: Problem 6 error

Post by quilan »

userProjectEuler wrote:the problem is asking:
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
which results in a negative value.
the problem should be reformulated to:
Find the difference between the square of the sum of the first one hundred natural numbers and the sum of the squares.

right?!!
result = abs( SquareOfSum(100) - SumOfSquares(100) )

If there was any ambiguity, the example should be enough to show that the answer should be positive.
ex ~100%'er... until the gf came along.
Image
userProjectEuler
Posts: 7
Joined: Sat Jul 25, 2009 8:52 pm

Re: Problem 6 error

Post by userProjectEuler »

quilan wrote:
userProjectEuler wrote:the problem is asking:
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
which results in a negative value.
the problem should be reformulated to:
Find the difference between the square of the sum of the first one hundred natural numbers and the sum of the squares.

right?!!
result = abs( SquareOfSum(100) - SumOfSquares(100) )

If there was any ambiguity, the example should be enough to show that the answer should be positive.
there's no ambiguity. the problem is asking a different thing. there's nothing mentioning that the result must be unsigned. but that is ok.
drsparky
Posts: 8
Joined: Fri Aug 14, 2009 12:47 pm

Problem 006 solution in O(1)

Post by drsparky »

I deleted my solution... apparently this is not the correct place. The forum in the puzzle is locked. That is so unfortunate. I was rather happy with my O(1) solution... :-(
User avatar
hk
Administrator
Posts: 12832
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: Problem 6 solution in O(1)

Post by hk »

The second and fourth post in the forum are O(1) too.
Please read the forum first.
Image
War ruins the life and health of untold numbers of innocent children.
drsparky
Posts: 8
Joined: Fri Aug 14, 2009 12:47 pm

Re: Problem 6 solution in O(1)

Post by drsparky »

Mine was different than both. Please don't be so condescending.
User avatar
daniel.is.fischer
Posts: 2400
Joined: Sun Sep 02, 2007 11:15 pm
Location: Bremen, Germany

Re: Problem 6 solution in O(1)

Post by daniel.is.fischer »

I doubt your solution will be fundamentally different from all posted variations of the sum formulae, but to check, could you please PM me your solution?
Il faut respecter la montagne -- c'est pourquoi les gypaètes sont là.
zwuupeape
Posts: 189
Joined: Tue Jun 09, 2009 6:11 pm

Re: Problem 6 solution in O(1)

Post by zwuupeape »

You can solve every problem in O(1).

Let x be the solution to problem y. In pseudocode:

### O(1) algorithm to solve problem y:
### t <- x
### output t
User avatar
stijn263
Posts: 1505
Joined: Sat Sep 15, 2007 11:57 pm
Location: Netherlands

Re: Problem 6 solution in O(1)

Post by stijn263 »

Actually, that solution is at least O( log x )
zwuupeape
Posts: 189
Joined: Tue Jun 09, 2009 6:11 pm

Re: Problem 6 solution in O(1)

Post by zwuupeape »

...what? How so? This program is O(1) by definition since its execution time is independent of input (it has no input) and it obviously halts.
User avatar
daniel.is.fischer
Posts: 2400
Joined: Sun Sep 02, 2007 11:15 pm
Location: Bremen, Germany

Re: Problem 6 solution in O(1)

Post by daniel.is.fischer »

How long does it take to output x (hint: if x is an integer, it has O(log |x|) digits 8-) )
Il faut respecter la montagne -- c'est pourquoi les gypa&egrave;tes sont l&agrave;.
zwuupeape
Posts: 189
Joined: Tue Jun 09, 2009 6:11 pm

Re: Problem 6 solution in O(1)

Post by zwuupeape »

daniel.is.fischer wrote:How long does it take to output x (hint: if x is an integer, it has O(log |x|) digits 8-) )
x is a constant, therefore log|x| is a constant...
User avatar
elendiastarman
Posts: 410
Joined: Sat Dec 22, 2007 8:15 pm

Re: Problem 6 solution in O(1)

Post by elendiastarman »

But not <=1 unless x only has one digit...
Want some
3.14159265358979323846264338327950288419716939937510
58209749445923078164062862089986280348253421170679...?
Image
zwuupeape
Posts: 189
Joined: Tue Jun 09, 2009 6:11 pm

Re: Problem 6 solution in O(1)

Post by zwuupeape »

O( 10^9999999999999999) = O(1)
User avatar
elendiastarman
Posts: 410
Joined: Sat Dec 22, 2007 8:15 pm

Re: Problem 6 solution in O(1)

Post by elendiastarman »

I think his point is that it will take longer to output a 100 digit answer rather than a 2 digit answer.
Want some
3.14159265358979323846264338327950288419716939937510
58209749445923078164062862089986280348253421170679...?
Image
zwuupeape
Posts: 189
Joined: Tue Jun 09, 2009 6:11 pm

Re: Problem 6 solution in O(1)

Post by zwuupeape »

It's true that it will take longer, but it will also take longer if you have a slower computer... Running time is measured relative to input. The running time of this algorithm is indeed O(|logx|) but O(|logx|) = O(1). Actually I don't even understand what's O(logx) supposed to mean. O(logn) means that the running time of the algorithm takes twice as long to halt if the input is raised to the power of 2. if 12 is the solution and it has 2 digits then what is O(2) supposed to mean?
Post Reply