[Haskell-beginners] Efficient sieve of erastothenes,
for solving project euler problem #10?
Malcolm Reynolds
malcolm.reynolds at gmail.com
Sun Nov 23 17:28:23 EST 2008
Hello all,
I'm attempting to learn Haskell by going through the project euler
problems. Number 10,
http://projecteuler.net/index.php?section=problems&id=10 , involves
summing prime numbers. It's easy in terms of coding something up that
works, but I'm having a lot of trouble getting decent performance.
I've learned a reasonable amount of ML at uni but Haskell is the first
lazy language I've used.. I think the inefficiency is possibly due to
the laziness but I'm not positive.
I'd love if someone could show me how to do this in Haskell somewhere
near as fast as C - at the moment I have a C version which runs in
about a tenth of a second (
http://github.com/malcster/project-euler-solutions--c-/tree/master/10.c
). My haskell attempts are
http://github.com/malcster/project-euler-solutions/tree/master/10better.hs
(using the sieve) and
http://github.com/malcster/project-euler-solutions/tree/master/10.hs
(using possibly an even worse method, but seems to be a bit faster).
If anyone could point out any neat strictness annotations or anything
else I could put in, that would be cool.
Cheers,
Malcolm
More information about the Beginners
mailing list