Created
February 22, 2015 05:41
-
-
Save nagat01/718017c507a8c14cc46b to your computer and use it in GitHub Desktop.
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
| {-# LANGUAGE ScopedTypeVariables #-} | |
| import qualified Data.IntSet as Set | |
| import Data.List(foldl') | |
| sieve n = step [2] (Set.fromList [3, 5 .. n]) | |
| where | |
| step ps cs = | |
| case Set.minView cs of | |
| Just (p, cs) -> | |
| step (p:ps) $ foldl' (\cs x -> Set.delete x cs) cs [p, p * 2 .. n] | |
| Nothing -> ps | |
| main = print $ head $ sieve 10000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment