Created
July 1, 2014 12:26
-
-
Save utdemir/928d95918bb86e5d59b6 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] | |
turingPrimes = (filter (isPrime.binread) primes) | |
`using` (parListChunk 4096 rdeepseq) | |
main = do | |
args <- getArgs | |
let bitCount = read $ head args | |
let ps = takeWhile (< (2^bitCount)) turingPrimes | |
mapM_ print $ map (\ n -> (n, binread n)) ps | |
print $ length ps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment