Jump to content

Primality by trial division: Difference between revisions

(→‎{{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. Not a sieve of Eratosthenes'''.
<lang scala>def sieve(nums: Stream[Int]): Stream[Int] =
Stream.cons(nums.head, sieve((nums.tail).filter(_ % nums.head != 0)))
751

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.