daily pastebin goal
15%
SHARE
TWEET

Untitled

a guest May 16th, 2018 85 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.      
  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
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top