Two Plus Two Publishing LLC Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > Other Topics > Programming

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old 06-02-2011, 03:54 AM   #76
veteran
 
MrWooster's Avatar
 
Join Date: Mar 2007
Location: Shoving AK
Posts: 2,839
Re: Any interest in a Project Euler Group?

Python is more of a scripting language than Ruby
MrWooster is offline   Reply With Quote
Old 06-02-2011, 04:43 PM   #77
Pooh-Bah
 
Aceium's Avatar
 
Join Date: Jan 2007
Location: Kansas
Posts: 4,758
Re: Any interest in a Project Euler Group?

I'm liking Python a lot.

Got the first problem in 5 lines. Love short programs.
Aceium is online now   Reply With Quote
Old 06-02-2011, 11:28 PM   #78
old hand
 
sorrow's Avatar
 
Join Date: Apr 2008
Location: Perth, Western Australia
Posts: 1,500
Re: Any interest in a Project Euler Group?

Quote:
Originally Posted by MrWooster View Post
Python is more of a scripting language than Ruby
I've found its good for scripting and for OO in larger problems. So far it seems ideal for this problem set.

Feel free to pull from me again
sorrow is offline   Reply With Quote
Old 06-03-2011, 04:03 AM   #79
veteran
 
MrWooster's Avatar
 
Join Date: Mar 2007
Location: Shoving AK
Posts: 2,839
Re: Any interest in a Project Euler Group?

Have pulled in your latest changes... looks like you are running away with it at the moment.

As an interesting experiment, I am going to write some solutions in javascript and see how they compare speed wise to yours.
MrWooster is offline   Reply With Quote
Old 06-03-2011, 05:10 AM   #80
veteran
 
MrWooster's Avatar
 
Join Date: Mar 2007
Location: Shoving AK
Posts: 2,839
Re: Any interest in a Project Euler Group?

I have just committed my first solution that is written in javascript (using NodeJS as the interpretor).

I have also added a utils folder to the repository with a 'speedTest.py' script (https://github.com/guyht/2p2-Euler-P...s/speedTest.py). This takes one or more solutions, runs them multiple times and compares the average time taken to run each solution.

Code:
Usage:

speedTest.py -[hn] file1 file2 file3

Options:
         -n Number of times to test each solution, default 1000
         -h Display this usage information

Example:
       speedTest.py -n 500 ./user1/solution.py ./user2/solution.py
For example, comparing mine and Sorrows solutions for problem 1:

Code:
2p2-Euler-Project/utils$ ./speedTest.py -n 20 ../problem-1/mrwooster/solution.js ../problem-1/Sorrow/solution.py 
Running 20 times for each solution
Testing solution ../problem-1/mrwooster/solution.js
Average execution time: 0.210370731354
Testing solution ../problem-1/Sorrow/solution.py
Average execution time: 0.171406471729
So Sorrows solution is slightly faster than mine

Note: Both files must be executable (chmod +x) and they will both need environment declarations at the top (e.g. #!/usr/bin/env python).

Also, if you wish to run my solution you will need NodeJS installed.

MrWooster is offline   Reply With Quote
Old 06-03-2011, 05:42 AM   #81
old hand
 
sorrow's Avatar
 
Join Date: Apr 2008
Location: Perth, Western Australia
Posts: 1,500
Re: Any interest in a Project Euler Group?

Quote:
Originally Posted by MrWooster View Post
I have also added a utils folder to the repository with a 'speedTest.py' script (https://github.com/guyht/2p2-Euler-P...s/speedTest.py).
Nice!

Quote:
Code:
2p2-Euler-Project/utils$ ./speedTest.py -n 20 ../problem-1/mrwooster/solution.js ../problem-1/Sorrow/solution.py 
Running 20 times for each solution
Testing solution ../problem-1/mrwooster/solution.js
Average execution time: 0.210370731354
Testing solution ../problem-1/Sorrow/solution.py
Average execution time: 0.171406471729
So Sorrows solution is slightly faster than mine
Hmm - not my results:
Code:
../utils/speedTest.py -n 20 mrwooster/solution.js Sorrow/solution.py 
Running 20 times for each solution
Average execution time: 0.118206512928
Testing solution Sorrow/solution.py
Average execution time: 0.0457811713219
For amusement I also wrote solution-2.py
Testing solution Sorrow/solution-2.py
Average execution time: 0.0434150695801

I'm using a pretty stock Lenovo Thinkpad (circa 2007/2008?) + Ubuntu
sorrow is offline   Reply With Quote
Old 06-03-2011, 06:05 AM   #82
veteran
 
MrWooster's Avatar
 
Join Date: Mar 2007
Location: Shoving AK
Posts: 2,839
Re: Any interest in a Project Euler Group?

I think the actual execution times will vary a lot between different systems, but the comparison should always be the same....

Just re-written my solution in C and its much faster...

Code:
 ./speedTest.py ../problem-1/mrwooster/csolution ../problem-1/mrwooster/solution.js ../problem-1/Sorrow/solution.py 
Running 10 times for each solution
Testing solution ../problem-1/mrwooster/csolution
Average execution time: 0.0438689947128
Testing solution ../problem-1/mrwooster/solution.js
Average execution time: 0.173312973976
Testing solution ../problem-1/Sorrow/solution.py
Average execution time: 0.130370759964
MrWooster is offline   Reply With Quote
Old 06-03-2011, 06:19 AM   #83
veteran
 
MrWooster's Avatar
 
Join Date: Mar 2007
Location: Shoving AK
Posts: 2,839
Re: Any interest in a Project Euler Group?

I have updated speedTest.py to ignore output from the solutions so you dont have to manually remove the lines of numbers.
MrWooster is offline   Reply With Quote
Old 06-03-2011, 06:40 AM   #84
veteran
 
MrWooster's Avatar
 
Join Date: Mar 2007
Location: Shoving AK
Posts: 2,839
Re: Any interest in a Project Euler Group?

Hmm... I think comparing different languages with the speed test script is not going to be a fair comparison as the bulk of the time taken is loading up the environment. I profiled my javascript code in the application itself and it tool less than 1 millisecond to run.

So the speed test can be used to compare solutions in the same language (as the time taken to load the environment will be the same), but not when comparing different languages.
MrWooster is offline   Reply With Quote
Old 06-03-2011, 07:04 AM   #85
veteran
 
MrWooster's Avatar
 
Join Date: Mar 2007
Location: Shoving AK
Posts: 2,839
Re: Any interest in a Project Euler Group?

Sorrow, did my solution 2 in python so I could get a good comparison. Also speedTest.py now uses arrays to keep track of times (a little more accurate).

Our code is quite different but execution times are v similar. To be honest, I think that the programs at the moment are so small that it is almost impossible to compare their speeds...

Code:
Running 20 times for each solution
Testing solution ../problem-2/Sorrow/solution.py
Average execution time: 0.13228982687
Testing solution ../problem-2/mrwooster/solution.py
Average execution time: 0.133040070534
MrWooster is offline   Reply With Quote
Old 06-03-2011, 06:41 PM   #86
Pooh-Bah
 
Sholar's Avatar
 
Join Date: Jul 2007
Posts: 5,109
Re: Any interest in a Project Euler Group?

Quote:
Originally Posted by MrWooster View Post
Hmm... I think comparing different languages with the speed test script is not going to be a fair comparison as the bulk of the time taken is loading up the environment.
Definitely. You want to run the code that does the work N times, not the entire program. Also, compiler optimization (or lack thereof) is going to make a big difference. (And there may be something even more important than those two factors that I don't know about.)

Learning Python has been on my to do list for a while...maybe this isn't a half-bad way to start that.
Sholar is offline   Reply With Quote
Old 06-03-2011, 11:37 PM   #87
old hand
 
sorrow's Avatar
 
Join Date: Apr 2008
Location: Perth, Western Australia
Posts: 1,500
Re: Any interest in a Project Euler Group?

Quote:
Originally Posted by MrWooster View Post
Hmm... I think comparing different languages with the speed test script is not going to be a fair comparison as the bulk of the time taken is loading up the environment. I profiled my javascript code in the application itself and it tool less than 1 millisecond to run.

So the speed test can be used to compare solutions in the same language (as the time taken to load the environment will be the same), but not when comparing different languages.
I think loading the environment is a legitimate cost but...

Quote:
Originally Posted by MrWooster View Post
Sorrow, did my solution 2 in python so I could get a good comparison. Also speedTest.py now uses arrays to keep track of times (a little more accurate).

Our code is quite different but execution times are v similar. To be honest, I think that the programs at the moment are so small that it is almost impossible to compare their speeds...
This.

Better for testing might be problem 12 - takes about 6 seconds on my machine, and isn't the smartest algorithm or problem 14 - takes about 2 minutes and is brute force.

Sorrow
sorrow is offline   Reply With Quote
Old 06-04-2011, 09:27 AM   #88
veteran
 
Victor Kros's Avatar
 
Join Date: Nov 2008
Posts: 3,256
Re: Any interest in a Project Euler Group?

Hey guys, i like thinking about problems like this. So i might chime in from time to time. I am not very good at programming efficiently, so i hope to learn something about that here.

Sorrow did you use Mersenne primes to set an upper and lower bound for problem 12?

With problem 14 you can eliminate so many numbers. For example all numbers x<=500000 because 2x would produce a longer chain. In the same way you can eliminate all numbers of the form 3n+1. As well as the numbers for which y=(x*2-1)/3<=1000000 (if y is an integer) etc.
Victor Kros is offline   Reply With Quote
Old 06-04-2011, 10:01 AM   #89
veteran
 
Victor Kros's Avatar
 
Join Date: Nov 2008
Posts: 3,256
Re: Any interest in a Project Euler Group?

solved problem 14 in 3.416 seconds in matlab, it is brute force after eliminating some possibilities. Is one supposed to post the code itt? Or is that annoying?
matlab claims it took 0.000000 to do the first problem.

Last edited by Victor Kros; 06-04-2011 at 10:09 AM.
Victor Kros is offline   Reply With Quote
Old 06-04-2011, 10:48 AM   #90
old hand
 
sorrow's Avatar
 
Join Date: Apr 2008
Location: Perth, Western Australia
Posts: 1,500
Re: Any interest in a Project Euler Group?

Quote:
Originally Posted by Victor Kros View Post
Hey guys, i like thinking about problems like this. So i might chime in from time to time. I am not very good at programming efficiently, so i hope to learn something about that here.
I'm only an average programmer with no particular math skills, i'm doing the problems to get my brain working again.
Quote:
Originally Posted by Victor Kros View Post
Sorrow did you use Mersenne primes to set an upper and lower bound for problem 12?
The triangle number problem? I'm using a pretty simple factor generation method how would I use Mersenne primes?
Quote:
Originally Posted by Victor Kros View Post
With problem 14 you can eliminate so many numbers. For example all numbers x<=500000 because 2x would produce a longer chain.
Should have thought of that...
Quote:
Originally Posted by Victor Kros View Post
In the same way you can eliminate all numbers of the form 3n+1. As well as the numbers for which y=(x*2-1)/3<=1000000 (if y is an integer) etc.
Are you sure ?

I just added a rule to eliminate ((i % 3) -1) and it doesn't find the number with 525 in its sequence, which probably means i'm misunderstanding you.
Quote:
Originally Posted by Victor Kros View Post
solved problem 14 in 3.416 seconds in matlab, it is brute force after eliminating some possibilities. Is one supposed to post the code itt? Or is that annoying?
matlab claims it took 0.000000 to do the first problem.
We are publishing the code publicly in git repositories MrWoosters repo is at https://github.com/guyht/2p2-Euler-P...commits/master

Sorrow
sorrow is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -4. The time now is 09:36 PM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.
Copyright © 2008-2010, Two Plus Two Interactive