Created
December 23, 2015 08:12
-
-
Save begriffs/46c9e47e7c5a6a1afd62 to your computer and use it in GitHub Desktop.
Calculating list of primes less than n
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| primesTo :: Int -> [Int] | |
| primesTo n = removeHeadMultiples [2..n] | |
| where | |
| removeHeadMultiples same@(p:xs) | |
| | p*p > n = same -- short circuit factors greater than sqrt(n) | |
| | otherwise = p : removeHeadMultiples [x | x <- xs, x `rem` p > 0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment