Tiago Carvalho wrote:
I've done this a while ago. But if I remember correctly you only need to
verify 2, 3, and after that all primes will be forms of 6k+1 or 6k-1.
This made my code a lot faster at the time.
Don't know if this is faster in this case since you have to store values
in an arra
Michael P. wrote:
int sum = 2;
You have a serious bug here. Can you see what it is?
One thing that may help a little is that you need only loop from 2 to
sqrt(n) in the isPrime function, otherwise you end up testing for
factors > sqrt(n) twice. A factor over sqrt(n) must have a
corr
"Michael P." wrote in message
news:gqvksi$1r...@digitalmars.com...
Spacen Jasset Wrote:
Michael P. wrote:
> Hey, I've started to do some of the problems on Project Euler to
> practice my programming skills. I'm doing #10 right now, and I think
> I've got a working solution. It's just that
Michael P. wrote:
Spacen Jasset Wrote:
Michael P. wrote:
Hey, I've started to do some of the problems on Project Euler to practice my
programming skills. I'm doing #10 right now, and I think I've got a working
solution. It's just that it's way too slow.
Here's the link:
http://projecteuler.n
Spacen Jasset Wrote:
> Michael P. wrote:
> > Hey, I've started to do some of the problems on Project Euler to practice
> > my programming skills. I'm doing #10 right now, and I think I've got a
> > working solution. It's just that it's way too slow.
> > Here's the link:
> > http://projecteuler.n
Robert Fraser Wrote:
> Yeah that's shorter (vertically; it's almost as long in characters),
This is simpler and faster (runs in 2.19 seconds), and gives the same result,
xtakeWhile isn't required because xprimes already stops nicely when the given
max N is reached:
import d.func, d.primes, d.st
Robert Fraser wrote:
> bearophile wrote:
>> import d.func, d.primes, d.string;
>> void main() {
>> const int N = 1_000_000_000;
>> putr( sum(xtakeWhile((int i){ return i < N;}, xprimes(N))) );
>> }
>
> Yeah that's shorter (vertically; it's almost as long in characters), but
> how much li
bearophile wrote:
import d.func, d.primes, d.string;
void main() {
const int N = 1_000_000_000;
putr( sum(xtakeWhile((int i){ return i < N;}, xprimes(N))) );
}
Yeah that's shorter (vertically; it's almost as long in characters), but
how much lisp do you have to smoke to understand it?
Michael P. wrote:
Hey, I've started to do some of the problems on Project Euler to practice my
programming skills. I'm doing #10 right now, and I think I've got a working
solution. It's just that it's way too slow.
Here's the link:
http://projecteuler.net/index.php?section=problems&id=10
The co
Michael P. Wrote:
> But for 2 million, it takes quite a while, and an FAQ on the page said most
> problems are made with being run within a minute. Mine was gonna quite a bit
> longer.
This will not give you much practice in programming, but if you need primes
quickly you may use my xprimes:
h
On Tue, Mar 31, 2009 at 9:11 PM, Michael P. wrote:
> Hey, I've started to do some of the problems on Project Euler to practice my
> programming skills. I'm doing #10 right now, and I think I've got a working
> solution. It's just that it's way too slow.
> Here's the link:
> http://projecteuler.n
Hey, I've started to do some of the problems on Project Euler to practice my
programming skills. I'm doing #10 right now, and I think I've got a working
solution. It's just that it's way too slow.
Here's the link:
http://projecteuler.net/index.php?section=problems&id=10
The code works fine with s
12 matches
Mail list logo