mersenneforum.org  

Go Back   mersenneforum.org > Fun Stuff > Puzzles

Reply
 
Thread Tools
Old 2012-02-19, 02:07   #1
lavalamp
 
lavalamp's Avatar
 
Oct 2007
Manchester, UK

5·271 Posts
Default Project Euler #372

I'm sure a lot people here are already familiar with Project Euler, but nevertheless, I found the latest puzzle to be quite interesting and thought I'd share it here.

It's a fairly easy one to understand, but coming up with an elegant solution was extremely hard. So hard that I in fact did not manage it, and instead took a brute force approach, albeit a very well optimised one.

For anyone that wants to have at it, here's the link:
http://projecteuler.net/problem=372

Of course, there are many more problems on there that are fun too.
lavalamp is offline   Reply With Quote
Old 2012-02-21, 04:45   #2
Christenson
 
Christenson's Avatar
 
Dec 2010
Monticello

179510 Posts
Default

Project Euler is what lead me here!!!

Did you notice that you can immediately halve the size of the search space by noting that on one side of x=y, the answer is always even?
Christenson is offline   Reply With Quote
Old 2012-02-21, 23:21   #3
lavalamp
 
lavalamp's Avatar
 
Oct 2007
Manchester, UK

5·271 Posts
Default

Indeedily, I made many optimisations, but when all was said and done it was still a fairly long run time. Many people in the forum for that problem (which you can only see when you have completed the problem) had code that ran much much faster because they used far cleverer methods.
lavalamp is offline   Reply With Quote
Old 2012-02-22, 05:09   #4
Jaxon
 
Dec 2011

1810 Posts
Default

Very interesting. I drew a quick graph of the solution set for R(0,500), and it's definitely a very pretty pattern.
Attached Thumbnails
Click image for larger version

Name:	solutions.png
Views:	311
Size:	12.3 KB
ID:	7684  
Jaxon is offline   Reply With Quote
Old 2012-02-24, 09:14   #5
PdB
 
Feb 2012

11 Posts
Default

Quote:
Originally Posted by lavalamp View Post
...code that ran much much faster because they used far cleverer methods.
Among these "clever" methods, did you see by chance something ressembling to computing the following sum :

sqrt(2)-sqrt(1) + sqrt(4)-sqrt(3) + .... + sqrt(n+1)-sqrt(n) ?

And if so, do you know the name os such a serie ?
Many thanks
PdB is offline   Reply With Quote
Old 2012-02-24, 19:42   #6
Mini-Geek
Account Deleted
 
Mini-Geek's Avatar
 
"Tim Sorbera"
Aug 2006
San Antonio, TX USA

17·251 Posts
Default

Quote:
Originally Posted by PdB View Post
Among these "clever" methods, did you see by chance something ressembling to computing the following sum :

sqrt(2)-sqrt(1) + sqrt(4)-sqrt(3) + .... + sqrt(n+1)-sqrt(n) ?

And if so, do you know the name os such a serie ?
Many thanks
http://www.wolframalpha.com/input/?i...sqrt%28n%29%29
The sum from n=1 to m is equal to sqrt{m+1}-1. I don't know if such a series has a name, but it seems an awfully roundabout way of getting that value.
Mini-Geek is offline   Reply With Quote
Old 2012-02-24, 20:24   #7
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

838410 Posts
Default

Quote:
Originally Posted by Mini-Geek View Post
http://www.wolframalpha.com/input/?i...sqrt%28n%29%29
The sum from n=1 to m is equal to sqrt{m+1}-1. I don't know if such a series has a name, but it seems an awfully roundabout way of getting that value.
that's not how I interpreted his idea:

Code:
sum(X=2,8,sqrt(X)-sqrt(X-1);X=X+2)
is how I interpreted it

Code:
(16:21)>sum(X=1,6,sqrt(X)-sqrt(X-1))
seems to be how you seem to interpret it.
science_man_88 is offline   Reply With Quote
Old 2012-02-24, 20:57   #8
Mini-Geek
Account Deleted
 
Mini-Geek's Avatar
 
"Tim Sorbera"
Aug 2006
San Antonio, TX USA

17×251 Posts
Default

Quote:
Originally Posted by science_man_88 View Post
that's not how I interpreted his idea:

Code:
sum(X=2,8,sqrt(X)-sqrt(X-1);X=X+2)
is how I interpreted it

Code:
(16:21)>sum(X=1,6,sqrt(X)-sqrt(X-1))
seems to be how you seem to interpret it.
Oh, you're right, I didn't notice that n went up by 2 each time. This is the corrected one: http://www.wolframalpha.com/input/?i...%282*n-1%29%29 Wolfram Alpha wasn't able to equate it to a simple equation like the other one, but it does diverge.
Mini-Geek is offline   Reply With Quote
Old 2012-02-24, 21:36   #9
science_man_88
 
science_man_88's Avatar
 
"Forget I exist"
Jul 2009
Dumbassville

838410 Posts
Default

Quote:
Originally Posted by Mini-Geek View Post
Oh, you're right, I didn't notice that n went up by 2 each time. This is the corrected one: http://www.wolframalpha.com/input/?i...%282*n-1%29%29 Wolfram Alpha wasn't able to equate it to a simple equation like the other one, but it does diverge.
Code:
(16:15)>sum(X=2,2,sqrt(X)-sqrt(X-1);X=X+2)
%112 = 4
(16:15)>sum(X=2,4,sqrt(X)-sqrt(X-1);X=X+2)
%113 = 15
(16:15)>sum(X=2,6,sqrt(X)-sqrt(X-1);X=X+2)
%114 = 30
(16:15)>sum(X=2,8,sqrt(X)-sqrt(X-1);X=X+2)
%115 = 49
49-30=19
30-15=15
15-4=11

second order differences:

19-15=4
15-11 = 4

second order differences are the same ( and yes I tested at least one more of these now) so it starts for x steps in 4*x^2 ... :

the second order differences of the result of subtracting 4*x^2 from each appears to be constant at -4.
science_man_88 is offline   Reply With Quote
Old 2012-02-25, 16:30   #10
voidme
 
Feb 2012

67 Posts
Default

There's a pastebin for this problem http://pastebin.com/ZMk5jK1b

But it seems to be a very unoptimized algorithm
voidme is offline   Reply With Quote
Old 2012-02-25, 16:52   #11
lavalamp
 
lavalamp's Avatar
 
Oct 2007
Manchester, UK

5×271 Posts
Default

Quote:
Originally Posted by PdB View Post
Among these "clever" methods, did you see by chance something ressembling to computing the following sum :

sqrt(2)-sqrt(1) + sqrt(4)-sqrt(3) + .... + sqrt(n+1)-sqrt(n) ?

And if so, do you know the name os such a serie ?
Many thanks
I did not see anyone using such a method, and I'm also not sure how that method would work. The sum to sqrt(100)-sqrt(99) for example is 4.6324, but R(0,100) is given to be 3019.
lavalamp is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Project Euler jhs Puzzles 32 2021-01-19 04:05
Project Euler 486 lavalamp Puzzles 8 2015-02-04 14:28
Euler (6,2,5) details. Death Math 10 2011-08-03 13:49
Project Euler Mini-Geek Lounge 2 2009-10-23 17:19
Bernoulli and Euler numbers (Sam Wagstaff project) fivemack Factoring 4 2008-02-24 00:39

All times are UTC. The time now is 03:07.


Sat Jul 17 03:07:17 UTC 2021 up 50 days, 54 mins, 1 user, load averages: 1.48, 1.32, 1.31

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.