[erlang-questions] Prime numbers exercise from Project Euler
Stanislav Sedov
stas@REDACTED
Tue Jul 23 23:22:38 CEST 2013
On Tue, 23 Jul 2013 13:48:10 -0700
Jeremy Ong <jeremy@REDACTED> mentioned:
> http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
>
> I did a very cursory look at your code and it seems your approach to
> generating the primes is not very efficient. Also, I'd recommend
> adding it as you go to save memory (rather than storing all 2 million
> primes in memory and adding them at the end).
>
Yes, the sieve of Eratosthenes will most likely be the best
method here. There are also a lot of probablistic primality
tests available (e.g. Fermat test) that can speedup the detection significally:
http://en.wikipedia.org/wiki/Primality_test .
--
Stanislav Sedov
ST4096-RIPE
() ascii ribbon campaign - against html e-mail
/\ www.asciiribbon.org - against proprietary attachments
More information about the erlang-questions
mailing list