Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- derived from
- -- https://stackoverflow.com/questions/17892313/
- -- sieve-of-eratosthenes-with-wheel-factorization/17892352#17892352
- euler limit = ([2,3,5,7] ++) . g
- . takeWhile (<= limit) . scanl (+) 11
- . tail . cycle . (zipWith (-) =<< tail)
- $ [x | x <- [1..211], gcd x 210 == 1]
- where
- g xs@(x:ys) | x*x > limit = xs
- | otherwise = x : g (remMultsOf x ys)
- -- = x : g (remove (multsOf x xs) ys)
- -- where
- -- multsOf x xs = map (x*) xs -OR- = \y -> rem y x == 0
- -- remove xs ys = ys \\ xs -OR- = filter (not . xs) ys
- -- (\\) = Data.List.Ordered.minus
- remMultsOf x ys = r (x*x) ys ys
- where
- r m xs [] = []
- r m xs (h:t) | m == h = r (x*head xs) (tail xs) t
- | otherwise = h : r m xs t
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement