Primality by trial division: Difference between revisions
→Segmented Generate and Test: comment, for clarity
(→Segmented Generate and Test: use function that's already there) |
(→Segmented Generate and Test: comment, for clarity) |
||
Line 1,071:
primesST = 2 : 3 : sieve 5 9 (drop 2 primesST) (inits $ tail primesST) where
sieve x q ps (fs:ft) = filter (noDivsBy fs) [x,x+2..q-2] -- fs = [], [3], [3,5], ...
++ sieve (q+2) (head ps^2) (tail ps) ft</lang>
<code>inits</code> makes a stream of (progressively growing) prefixes of an input stream, starting with an empty prefix. <code>noDivsBy</code> is [[#Haskell|defined above]].
|