Created
July 1, 2014 13:33
-
-
Save utdemir/1eebf35b99d07a92eb5a 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
import System.Environment | |
import Control.Parallel.Strategies | |
import Math.NumberTheory.Primes.Sieve (primes) | |
import Math.NumberTheory.Primes.Testing (isPrime) | |
-- Converts 42d -> 101010d | |
binread :: Integer -> Integer | |
binread 0 = 0 | |
binread n = let (q, r) = n `divMod` 2 | |
in r + 10 * binread q | |
turingPrimes :: [(Integer, Bool)] | |
turingPrimes = map (\ i -> (i, isPrime $ binread i)) primes | |
main = do | |
args <- getArgs | |
let bitCount = read $ head args | |
let ps = takeWhile ((< 2^bitCount).fst) turingPrimes | |
let par = ps `using` (parListChunk 100000 rdeepseq) | |
print $ length $ filter snd par |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment