Last active
August 29, 2015 14:03
-
-
Save utdemir/956c3bd5a6dd13a1f33a 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 | |
main = do | |
args <- getArgs | |
let bitCount = read $ head args | |
let ps = takeWhile (< (2^bitCount)) turingPrimes | |
let out = (map (\ n -> (n, binread n)) ps) `using` | |
(parListChunk 100000 rdeepseq) | |
mapM_ print out | |
print $ length out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment