Advertisement
Guest User

Untitled

a guest
May 16th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. -- derived from
  2. -- https://stackoverflow.com/questions/17892313/
  3. -- sieve-of-eratosthenes-with-wheel-factorization/17892352#17892352
  4.  
  5. euler limit = ([2,3,5,7] ++) . g
  6. . takeWhile (<= limit) . scanl (+) 11
  7. . tail . cycle . (zipWith (-) =<< tail)
  8. $ [x | x <- [1..211], gcd x 210 == 1]
  9. where
  10. g xs@(x:ys) | x*x > limit = xs
  11. | otherwise = x : g (remMultsOf x ys)
  12.  
  13. remMultsOf x ys = r (x*x) ys ys
  14. where
  15. r m xs [] = []
  16. r m xs (h:t) | m == h = r (x*head xs) (tail xs) t
  17. | otherwise = h : r m xs t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement