Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. wl = [2,4,2,4,6,2,6,4,2,4,6,6,2,6,4,2,6,4,6,8,4,2,4,2,4,8,6,4,6,2,4,6,2,6,6,4,2,4,6,2,6,4,2,4,2,10,2,10]
  2. -- the so-called wheel: the recurring pattern in a composite punctuated list
  3. n7sl = scanl (+) 11 $ cycle wl -- infinite
  4.  
  5. -- short list of composits with no 2's, 3's 5's or 7's; 77%+ reduced
  6. n7s = take 150 $ n7sl
  7.  
  8. -- diagonalize and limit the factor's composite list
  9. lls i y = drop i.take y $ n7sl
  10.  
  11. -- substract the 1st list from the 2nd, infinite list
  12. rms [] _ = [] -- stop when first list is exhausted
  13. rms n@(x:xs) p@(y:ys)
  14. | x==y = rms xs ys
  15. | x>y = y:rms n ys
  16. | y>x = rms xs p
  17.  
  18. -- generate the composite list
  19. comps [] _ _ _ _ =[]
  20. comps (n:ns) [] y i b = comps ns (lls (i+1) y) y (i+1) b
  21. comps k@(n:ns) (r:rs) y i b
  22. | m>b =comps ns (lls (i+1) y) y (i+1) b
  23. | m<=b =m:comps k rs y i b
  24. where m = n*r
  25.  
  26. -- the result of `comps` is not just a diagonalization but 2, top & irregular bottom
  27. -- `comps` is maybe necessary to stop when the limit of a list is reached
  28. -- otherwise, I was using a list comprehension which is way less complicated
  29.  
  30. -- `comps` has to many parameters so this to reduce it to 1
  31. -- it will be subtracted the fixed length wheel numbers and the lazy wheel
  32. comp1 n =sort $ comps n7s (lls 0 n) n 0 (11*(last.take n $ n7sl))
  33. -- put everything together to generate primes
  34.  
  35. comp1 y = sort [ m
  36. | (i,n) <- zip [0..149] n7sl
  37. , m <- takeWhile ((<= 11 * last (take y n7sl))) $ map (n*) $ drop i $ take n n7sl
  38. ]
  39.  
  40. t = sort [ m | bs@(a:_) <- tails n7s,
  41. m <- takeWhile (<= 11*last n7s) $ map (a*) bs]
  42.  
  43. calcc _ _ []= []
  44. calcc f lim (x:xs)
  45. | m<= lim= m:calcc f lim xs
  46. | True= []
  47. where m= f*x
  48.  
  49. runr _ []= []
  50. runr lim xss@(x:xs) = (calcc x lim xss)++runr lim xs
  51.  
  52. rrunr n = runr lim ds
  53. where ds= take n n7sl
  54. lim= 11*last ds
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement