Problem 001

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.
Post Reply
User avatar
Slaunger
Posts: 40
Joined: Tue Jul 20, 2010 12:23 am

Re: Problem 001

Post by Slaunger »

Plebian wrote:Edit2: Forum thread's closed but.. wow. The other Python solutions are much more complex and shorter than mine.
I recall having had the same experience, when I first saw the first forum thread. Now, I advice to study those smarter solutions and understand how they work; that will boost your Python programming and math skills and better enable you to solve the next problem - and the next problem - and... - at least that is how it worked for me :D
Image
rjashton
Posts: 2
Joined: Mon Jul 18, 2011 3:47 pm

Re: Problem 001

Post by rjashton »

Hibernatus34 wrote:
rjashton wrote:So I managed to solve this one fairly quickly but I was wondering: if I can't post my code here where can I post it?
Do you think your code would interest any of us ?
Does it use a revolutionary formula ? (you can't even call it an algorithm for this problem)
If not, why do you want to post your code somewhere ?
Have you read the forum and the PDF ? Haven't you found the exact same solution as yours ?
Jeez, what did you get stuck where the sun don't shine?

Thanks for the warm welcome to the community.

Here's a riddle for you: what's the point in a forum where someone asking to discuss something isn't allowed to and is castigated for even asking where?
User avatar
hk
Administrator
Posts: 12832
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: Problem 001

Post by hk »

rjashton wrote:
Hibernatus34 wrote:
rjashton wrote:So I managed to solve this one fairly quickly but I was wondering: if I can't post my code here where can I post it?
Do you think your code would interest any of us ?
Does it use a revolutionary formula ? (you can't even call it an algorithm for this problem)
If not, why do you want to post your code somewhere ?
Have you read the forum and the PDF ? Haven't you found the exact same solution as yours ?
Jeez, what did you get stuck where the sun don't shine?

Thanks for the warm welcome to the community.

Here's a riddle for you: what's the point in a forum where someone asking to discuss something isn't allowed to and is castigated for even asking where?
Look here rjashton,
As of date this problem is solved by 161862 people.
Let's do an estimate.
Suppose one out of 20 of those people want to post their solution that would mean more than 8000 posts to wade through.
Please try to understand that we don't reserve the space for that, simply because it would mean that the same would be repeated over and over again.
Image
War ruins the life and health of untold numbers of innocent children.
Hibernatus34
Posts: 31
Joined: Mon May 16, 2011 7:03 am

Re: Problem 001

Post by Hibernatus34 »

rjashton wrote: Jeez, what did you get stuck where the sun don't shine?

Thanks for the warm welcome to the community.

Here's a riddle for you: what's the point in a forum where someone asking to discuss something isn't allowed to and is castigated for even asking where?
Let me apologize, i didn't mean to sound harsh. I'm a new user, just like you, i don't talk in the name of a "community". Don't feel uncomfortable about asking questions here just because of my post.
I have yet to understand why so many people want to post their useless code.
I wish there was a page dedicated to that, separate from the forums, so everyone would be satisfied.
Image Joined PE in May 2011
User avatar
Lord_Farin
Posts: 239
Joined: Wed Jul 01, 2009 10:43 am
Location: Netherlands

Re: Problem 001

Post by Lord_Farin »

Hibernatus34 wrote: I have yet to understand why so many people want to post their useless code.
I wish there was a page dedicated to that, separate from the forums, so everyone would be satisfied.
Cf. viewtopic.php?f=5&t=1421&p=26961#p26961
Image
User avatar
Vithmaldonst
Posts: 3
Joined: Sun Jul 24, 2011 10:09 am

Regarding Problem 001

Post by Vithmaldonst »

I was wondering if there is any place at all I can discuss the solution in detail on this site?

After spending a couple hours on this problem and finding a truly elegant solution, I was dismayed to see the solutions other people had submitted, and the general state of the solutions thread. I was under the impression from the 'about' section of the site that said thread would be a place where people discussed how to find the simplest and most elegant solutions to problems. Instead it was just a repository for people posting their code, usually poorly written, without adequate commenting and with no explanation.

I'm posting this because I generalized the solution and derived a simple 2nd degree polynomial that would give (or approximate for most values) the solution at ANY point, not just 1000. I think people would be interested in seeing it and I'd be interested in discussing taking the solution a step or two further. Reading through the 38 page solution thread for this problem, I did not find a single other person who found this solution, nor anyone who came close. There were only a handful who even attempted a mathematical solution to begin with.
Image
TripleM
Posts: 384
Joined: Fri Sep 12, 2008 3:31 am

Re: Problem 001

Post by TripleM »

Did you read the PDF for the problem? (See the PDF icon on the problems overview page)
User avatar
hk
Administrator
Posts: 12832
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: Problem 001

Post by hk »

Did you read the PDF for this problem?
You can find it directly to the right of the green tick for this problem on the problems page.
Is your solution better than the method developed there?
Do you think the method there can be developed any further?
Do you think that there exists a better solution than the one given there?

(cross posted with TripleM)
Image
War ruins the life and health of untold numbers of innocent children.
User avatar
Vithmaldonst
Posts: 3
Joined: Sun Jul 24, 2011 10:09 am

Re: Problem 001

Post by Vithmaldonst »

hk wrote:Did you read the PDF for this problem?
You can find it directly to the right of the green tick for this problem on the problems page.
Is your solution better than the method developed there?
Do you think the method there can be developed any further?
Do you think that there exists a better solution than the one given there?

(cross posted with TripleM)
Thanks for the quick response. And yes, I read the .pdf. My solution is definitely better than any iterative approach, or even the Gaussian approach as it allows for the computation of the solution directly by using a simple polynomial. The method there can be developed further by showing a repeating pattern that occurs in groupings of partial sums. Noticing this pattern allowed me to formulate the sum in terms of a single mathematical expression, which lead to the aforementioned solution.
Image
User avatar
hk
Administrator
Posts: 12832
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: Problem 001

Post by hk »

In my opinion a solution that approximates the answer in most cases isn't a solution.

The solution in the PDF uses also a polynomial and does not approximate anything . It does not need be developed further spotting patterns. It is O(1).
(The Gaussian method is a polynomial of degree two).
Please study it thoroughly as there is no better method.
Image
War ruins the life and health of untold numbers of innocent children.
User avatar
Vithmaldonst
Posts: 3
Joined: Sun Jul 24, 2011 10:09 am

Re: Problem 001

Post by Vithmaldonst »

In my opinion a solution that approximates the answer in most cases isn't a solution.
A polynomial is a continuous function, but the sum of numbers divisible by 3 or 5 is not continuous. Thus it is not exact for values which are not numbers which are divisible by 3 or 5... which are most numbers.
The solution in the PDF uses also a polynomial and does not approximate anything . It does not need be developed further spotting patterns. It is O(1).
(The Gaussian method is a polynomial of degree two).
Please study it thoroughly as there is no better method.
I actually just noticed that this approach does indeed simplify to the polynomial I derived. Still, the simplified polynomial requires less computation than the example given. :(
Image
User avatar
Francky
Posts: 90
Joined: Sat May 07, 2011 3:49 pm
Location: South of France

Re: Problem 001

Post by Francky »

The only thing that would be better in solutions yet presented is an optimized function

Code: Select all

int f(tabular tab, int limit);   //pseudo code
who give the number of multiple (of each int in tab) less than limit.
ImageEntia non sunt multiplicanda praeter necessitatem
User avatar
hk
Administrator
Posts: 12832
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: Problem 001

Post by hk »

Vithmaldonst wrote:
In my opinion a solution that approximates the answer in most cases isn't a solution.
A polynomial is a continuous function, but the sum of numbers divisible by 3 or 5 is not continuous. Thus it is not exact for values which are not numbers which are divisible by 3 or 5... which are most numbers.
But you are required to solve a "not continuous problem".
Many problems on Project Euler are about "not continuous problems".
Most of the time they require somewhat different solution methods than continuous ones to get the exact answer.
Image
War ruins the life and health of untold numbers of innocent children.
agrubner
Posts: 8
Joined: Fri Feb 17, 2012 12:19 pm

Re: Problem 001

Post by agrubner »

Dear Program Admins

I tried to resolve problem 001. "Tried" is maybe the wrong declaration, but there is some bug around which prevents me to go further.

Here again the task: "If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000."

The sample with the numbers < 10 is correct with my code. But < 1000 is not. How can I post a code, that you could kindly check it?

Here is my output for value < 15.

zähler: 0
..addiere 0 + 0 = 0
zähler: 3
..addiere 3 + 0 = 3
zähler: 6
..addiere 6 + 3 = 9
zähler: 9
..addiere 9 + 9 = 18
zähler: 12
..addiere 12 + 18 = 30
All numbers multiple by 3 < 15 = 30
zähler: 0
..addiere 0 + 0 = 0
zähler: 5
..addiere 5 + 0 = 5
zähler: 10
..addiere 10 + 5 = 15
All numbers multiple by 5 < 15 = 15
The sum of the two subsum = 45

When I do it for < 1000, then I always get a wrong result back: The number for my calculation is: 22548.

Can you give me some help please?
User avatar
hk
Administrator
Posts: 12832
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: Problem 001

Post by hk »

What would your output be for value<35?
Please inspect that output carefully.
Image
War ruins the life and health of untold numbers of innocent children.
agrubner
Posts: 8
Joined: Fri Feb 17, 2012 12:19 pm

Re: Problem 001

Post by agrubner »

Dear Admin

When I increase the value to 35, then I got the following:

zähler: 0
..addiere 0 + 0 = 0
zähler: 3
..addiere 3 + 0 = 3
zähler: 6
..addiere 6 + 3 = 9
zähler: 9
..addiere 9 + 9 = 18
zähler: 12
..addiere 12 + 18 = 30
zähler: 15
..addiere 15 + 30 = 45
zähler: 18
..addiere 18 + 45 = 63
zähler: 21
..addiere 21 + 63 = 84
zähler: 24
..addiere 24 + 84 = 108
zähler: 27
..addiere 27 + 108 = 135
zähler: 30
..addiere 30 + 135 = 165
zähler: 33
..addiere 33 + 165 = 198
All numbers multiple by 3 < 35 = 198
zähler: 0
..addiere 0 + 0 = 0
zähler: 5
..addiere 5 + 0 = 5
zähler: 10
..addiere 10 + 5 = 15
zähler: 15
..addiere 15 + 15 = 30
zähler: 20
..addiere 20 + 30 = 50
zähler: 25
..addiere 25 + 50 = 75
zähler: 30
..addiere 30 + 75 = 105
All numbers multiple by 5 < 35 = 105
The sum of the two subsum = 303

Correct or not?
User avatar
jaap
Posts: 588
Joined: Tue Mar 25, 2008 3:57 pm
Contact:

Re: Problem 001

Post by jaap »

agrubner wrote:Correct or not?
It is correctly doing what you programmed it to do, but it is not quite the correct solution to the problem.

Heed hk's advice:
hk wrote:Please inspect that output carefully.
In particular:
Expand
[quote="agrubner"]zähler: 12
..addiere 12 + 18 = 30
zähler: 15
..addiere 15 + 30 = 45
zähler: 18
..addiere 18 + 45 = 63

...

zähler: 10
..addiere 10 + 5 = 15
zähler: 15
..addiere 15 + 15 = 30
zähler: 20
..addiere 20 + 30 = 50[/quote]
agrubner
Posts: 8
Joined: Fri Feb 17, 2012 12:19 pm

Re: Problem 001

Post by agrubner »

Dear jaap & hk

I think it is the logical or and not and, right? The problem is the duplicate 15... . If yes, then I need a bit more time again to think. about it. But the thing is, a logical or is true,when a and b are true same time.

I will check it again.

Cheers
agrubner
User avatar
Marcus_Andrews
Administrator
Posts: 1637
Joined: Wed Nov 09, 2011 5:23 pm

Re: Problem 001

Post by Marcus_Andrews »

agrubner wrote:Dear jaap & hk

I think it is the logical or and not and, right? The problem is the duplicate 15... . If yes, then I need a bit more time again to think. about it. But the thing is, a logical or is true,when a and b are true same time.

I will check it again.

Cheers
agrubner
Try to see if you can solve the problem by just iterating once over the relevant range of numbers. You shouldn't run into duplication errors that way and it'll help you formulate the solution by focusing on the logic.
agrubner
Posts: 8
Joined: Fri Feb 17, 2012 12:19 pm

Re: Problem 001

Post by agrubner »

Dear all

I wrote the numbers (multiple by 3 and multiple by 5) to see where we have duplicate entries. Here a small extract of that table.

3 5
6 10
9 15
12 20
15 25
18 30
21 35
24 40
27 45
30 50
33 55
36 60
39 65
42 70
45 75
48 80
51 85
54 90
57 95
60 100
63 105

For the example with the final result < 35, I receive now the following value:

zähler: 0
..addiere 0 + 0 = 0
zähler: 3
..addiere 3 + 0 = 3
zähler: 6
..addiere 6 + 3 = 9
zähler: 9
..addiere 9 + 9 = 18
zähler: 12
..addiere 12 + 18 = 30
zähler: 15
..addiere 15 + 30 = 45
zähler: 18
..addiere 18 + 45 = 63
zähler: 21
..addiere 21 + 63 = 84
zähler: 24
..addiere 24 + 84 = 108
zähler: 27
..addiere 27 + 108 = 135
zähler: 30
..addiere 30 + 135 = 165
zähler: 33
..addiere 33 + 165 = 198
All numbers multiple by 3 < 35 = 198
zähler: 0
..addiere 0 + 0 = 0
zähler: 5
..addiere 5 + 0 = 5
zähler: 10
..addiere 10 + 5 = 15
zähler: 15
..addiere 15 + 15 = 30
zähler: 20
..addiere 20 + 30 = 50
zähler: 25
..addiere 25 + 50 = 75
zähler: 30
..addiere 30 + 75 = 105
All numbers multiple by 5 < 35 = 105
zähler: 0
..addiere 0 + 0 = 0
zähler: 15
..addiere 15 + 0 = 15
zähler: 30
..addiere 30 + 15 = 45
All duplicates to remove = 45
The sum of the two subsum = 303
The total minus the duplicates = 258

Is that correct the way it is supposed to be?

Thanks again for your help, much appreciated.

Cheers
Alex
Post Reply