Page 9 of 13
Posted: Sun Aug 12, 2007 9:46 pm
by michaeled314
Here's some translated code from the Euler forum
Code: Select all
!XOR edx,edx
MOV eax,3
While eax < 1000
ADD edx,eax
ADD eax,3
Wend
MOV eax,5
While eax < 1000
ADD edx,eax
ADD eax,15
Wend
MOV eax,10
While eax < 1000
ADD edx,eax
ADD eax,15
Wend
a !DB
MOV a,edx
Debug a
Posted: Sun Aug 12, 2007 10:12 pm
by dioxin
michaeled314,
should this:
Code: Select all
While eax < 1000
ADD edx,eax
ADD eax,15
Wend
not be this:
Code: Select all
While eax < 1000
SUB edx,eax
ADD eax,15
Wend
Paul.
Posted: Mon Aug 13, 2007 1:13 am
by Dreamland Fantasy
dioxin wrote:I think to start with you need a much more efficient IsPrime() function and a more efficient find next prime function.
There is mention of a pseudo-prime test on the Project Euler forum, but to be honest I haven't been able to get my head around how that works yet.
Kind regards,
Francis.
Posted: Mon Aug 13, 2007 1:40 am
by dioxin
Francis,
I get the impression that there are tests (Rabin-Miller? and similar) which tell you that a number is very likely to be prime and very quickly.
When searching lots of primes it might be an idea to first do the quick test which will probably give a good answer and then afterwards use the much slower brute force method to verify that answer.
That way the time consuming brute force method is only carried out on numbers which are very likely to be prime instead of all numbers in the range.
I've just had a quick look at such a test ..
http://aspn.activestate.com/ASPN/Cookbo ... /index_txt
and you're right. They take a bit understanding!
But, presumably, you need to use such a test to get anywhere near solving these problems in the time scale suggested.
Paul.
Posted: Mon Aug 13, 2007 2:55 am
by michaeled314
How on earth would you do #2 in ASM
Posted: Mon Aug 13, 2007 12:05 pm
by Dreamland Fantasy
I've managed to get problem 146 solved in about 3.5 minutes (and that's on a Pentium4 @ 1.6GHz, not my quad-core machine).
A simple trick to completing it really fast is to create a function that will check n^2 + 1, n^2 + 3, n^2 + 7, etc.. for primes simultaneously rather than doing them individually with IsPrime().
*** EDIT: I've just refined my routine so that it now completes in just over a minute!
Kind regards,
Francis.
Posted: Mon Aug 13, 2007 2:15 pm
by Michael Vogel
Dreamland Fantasy wrote:
A simple trick to completing it really fast is to create a function that will check n^2 + 1, n^2 + 3, n^2 + 7, etc.. for primes simultaneously rather than doing them individually with IsPrime().
Hi Francis,
have it also here on my notebook in about a minute now - except the precalculation time for the primes (but this should be done in about 10 seconds

)
Just used my old code (seen in page 8 of the thread, so I also check all terms in the IsPrimeChain() at the beginning) - so the only real change is that I have removed the precalculation of primes (saved it to a file)
Thanks for all tips

, so I can remove one more from my list...
Michael
PS problem 144 is maybe the only one which needs (?) to be solved with floating point variables, but on the other hand calculation time is nearly null...
Posted: Mon Aug 13, 2007 4:44 pm
by Dreamland Fantasy
Michael Vogel wrote:Just used my old code (seen in page 8 of the thread, so I also check all terms in the IsPrimeChain() at the beginning) - so the only real change is that I have removed the precalculation of primes (saved it to a file)
Yeah, I've saved the pre-calculated primes upto 150000000 on my computer at home, but it's quite a big file (too big for my memory stick)!
I redone the pre-calculations and saved them on this computer and redoing the problem it completes in 15.6 seconds (P4 @ 1.6GHz)! Pre-calculating to 79000 and doing the rest on the fly takes 64.4 seconds, so it's a big speed boost!
Kind regards,
Francis.
Posted: Mon Aug 13, 2007 8:19 pm
by Michael Vogel
Dreamland Fantasy wrote:Yeah, I've saved the pre-calculated primes upto 150000000 on my computer at home, but it's quite a big file (too big for my memory stick)!
I redone the pre-calculations and saved them on this computer and redoing the problem it completes in 15.6 seconds (P4 @ 1.6GHz)! Pre-calculating to 79000 and doing the rest on the fly takes 64.4 seconds, so it's a big speed boost!
Hey Francis, you are #1! (not only because you started with this problem)
Never will get these results, precalculation takes about two or three minutes here! (Maybe you can PM me your code;), I saved the primes only, which takes about 33MB when using long values...
Again, 16 (and also 64) seconds are great!
Michael
Posted: Mon Aug 13, 2007 8:23 pm
by michaeled314
michaeled314 wrote:How on earth would you do #2 in ASM
:roll:
Posted: Mon Aug 13, 2007 9:56 pm
by Dreamland Fantasy
Michael Vogel wrote:Dreamland Fantasy wrote:Yeah, I've saved the pre-calculated primes upto 150000000 on my computer at home, but it's quite a big file (too big for my memory stick)!
I redone the pre-calculations and saved them on this computer and redoing the problem it completes in 15.6 seconds (P4 @ 1.6GHz)! Pre-calculating to 79000 and doing the rest on the fly takes 64.4 seconds, so it's a big speed boost!
Hey Francis, you are #1! (not only because you started with this problem)
Never will get these results, precalculation takes about two or three minutes here! (Maybe you can PM me your code;), I saved the primes only, which takes about 33MB when using long values...
Again, 16 (and also 64) seconds are great!
Michael
I was looking forward to trying out the code on my machine at home, but unfortunately I left my memory stick at work. Doh! :roll: In theory it should take about 2 seconds give or take on my quad-core system. Quite impressive I think considering my original approach took over 4 days!
I'll PM you my code tomorrow if I get the chance.
My saved list of primes takes up around 33MB too (too big for a 32MB stick!). You've probably just done the same as me and used WriteLong() to save the values to the file.
Kind regards,
Francis.
Posted: Tue Aug 14, 2007 1:54 am
by pdwyer
Are you guys doing some sort of group entry for this or are you all submitting independantly? This looks kind of fun.
I'm wondering if this is a collaborative effort or you are just sharing notes as you go
Posted: Tue Aug 14, 2007 3:56 am
by michaeled314
michaeled314 wrote:michaeled314 wrote:How on earth would you do #2 in ASM
:roll:
:roll: :roll:
Posted: Tue Aug 14, 2007 9:11 am
by Dreamland Fantasy
pdwyer wrote:Are you guys doing some sort of group entry for this or are you all submitting independantly? This looks kind of fun.
I'm wondering if this is a collaborative effort or you are just sharing notes as you go
I'm doing this independently, but I do try to help out others if I can as well as asking for help myself if I need a nudge in the right direction.
It's also good for sharing tidbits of information and code if someone has a better way of doing something.
Kind regards,
Francis.
Posted: Tue Aug 14, 2007 9:14 am
by Dreamland Fantasy
michaeled314 wrote:michaeled314 wrote:michaeled314 wrote:How on earth would you do #2 in ASM
:roll:
:roll: :roll:
Try having a look at
http://www.csn.ul.ie/~darkstar/assembler/.
Sorry I can't be of much more help than that, but x86 assembly really isn't my forte at present.
Kind regards,
Francis