Euler Sieve

Euler's sieve progressively removes, from all the natural numbers above 1, all the multiples of primes as the primes are found by it, starting with 2.

Closely related to the SieveOfEratosthenes.

In HaskellLanguage,

 primes = euler [2..]
 euler (x:xs) = x : euler (xs `minus` map (*x) (x:xs))
(this code uses "minus" from DataListOrdered package, with obvious semantics; is due to Daniel Fischer, posted on haskell-cafe mailing list).


EditText of this page (last edited October 26, 2011) or FindPage with title or text search