Sieve of Eratosthenes: Difference between revisions

→‎Tree-merging incremental sieve: no primed names please -- the highlighting is horrendous with those
(Add Draco)
(→‎Tree-merging incremental sieve: no primed names please -- the highlighting is horrendous with those)
Line 8,661:
_U ((x:xs):t) = x : (merge xs . _U . pairs) t -- tree-shaped folding big union
pairs (xs:ys:t) = merge xs ys : pairs t
merge xs@(x:xs'xt) ys@(y:ys'yt) | x < y = x : merge xs'xt ys
| y < x = y : merge xs ys'yt
| otherwise = x : merge xs'xt ys'yt</lang>
 
Works with odds only, the simplest kind of wheel. Here's the [http://ideone.com/qpnqe test entry] on Ideone.com, and a [http://ideone.com/p0e81 comparison with more versions].
751

edits