fork download
  1. {-# OPTIONS_GHC -O2 -fno-cse #-}
  2. primesTMWE = 2:3:5:7: gapsW 11 wheel (joinT3 $ rollW 11 wheel primes')
  3. where
  4. primes' = 11: gapsW 13 (tail wheel) (joinT3 $ rollW 11 wheel primes')
  5.  
  6. gapsW k ws@(w:t) cs@(c:u) | k==c = gapsW (k+w) t u
  7. | True = k : gapsW (k+w) t cs
  8. rollW k ws@(w:t) ps@(p:u) | k==p = scanl (\c d->c+p*d) (p*p) ws
  9. : rollW (k+w) t u
  10. | True = rollW (k+w) t ps
  11. joinT3 ((x:xs): ~(ys:zs:t)) = x : union xs (union ys zs)
  12. `union` joinT3 (pairs t)
  13. wheel = 2:4:2:4:6:2:6:4:2:4:6:6:2:6:4:2:6:4:6:8:4:2:4:2:
  14. 4:8:6:4:6:2:4:6:2:6:6:4:2:4:6:2:6:4:2:4:2:10:2:10:wheel
  15.  
  16. main = mapM_ print
  17. . take 10 . map fst
  18. . tail . iterate (splitAt 10.snd)
  19. $ ([],take 100 primesTMWE)
  20.  
  21. pairs ((x:xs):ys:t) = (x : union xs ys) : pairs t
  22. union (x:xs) (y:ys) = case (compare x y) of
  23. LT -> x : union xs (y:ys)
  24. EQ -> x : union xs ys
  25. GT -> y : union (x:xs) ys
  26.  
Success #stdin #stdout 0s 5740KB
stdin
Standard input is empty
stdout
[2,3,5,7,11,13,17,19,23,29]
[31,37,41,43,47,53,59,61,67,71]
[73,79,83,89,97,101,103,107,109,113]
[127,131,137,139,149,151,157,163,167,173]
[179,181,191,193,197,199,211,223,227,229]
[233,239,241,251,257,263,269,271,277,281]
[283,293,307,311,313,317,331,337,347,349]
[353,359,367,373,379,383,389,397,401,409]
[419,421,431,433,439,443,449,457,461,463]
[467,479,487,491,499,503,509,521,523,541]