Advertisement
Guest User

Untitled

a guest
May 16th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.                         --      = x : g (remove (multsOf x xs) ys)
  13.                         -- where
  14.                         --    multsOf x xs = map (x*) xs    -OR-   = \y -> rem y x == 0
  15.                         --    remove xs ys = ys \\ xs       -OR-   = filter (not . xs) ys
  16.                                             -- (\\) = Data.List.Ordered.minus
  17.       remMultsOf x ys = r (x*x) ys ys
  18.          where
  19.          r m xs []                = []
  20.          r m xs (h:t) | m == h    =     r (x*head xs) (tail xs)  t
  21.                       | otherwise = h : r   m               xs   t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement