Primality by trial division: Difference between revisions
→Odds-Only "infinite" primes generator using Streams and Co-Inductive Streams
(→{{header|Scala}}: move TD-sieve from SoE as per talk page discussion there) |
|||
Line 2,209:
===Odds-Only "infinite" primes generator using Streams and Co-Inductive Streams===
Using Streams, [http://www.cs.hmc.edu/~oneill/papers/Sieve-JFP.pdf the "unfaithful sieve"], i.e. '''sub-optimal trial division sieve
<lang scala>def sieve(nums: Stream[Int]): Stream[Int] =
Stream.cons(nums.head, sieve((nums.tail).filter(_ % nums.head != 0)))
|