Skip to content

Instantly share code, notes, and snippets.

@utdemir
Last active August 29, 2015 14:03
Show Gist options
  • Save utdemir/956c3bd5a6dd13a1f33a to your computer and use it in GitHub Desktop.
Save utdemir/956c3bd5a6dd13a1f33a to your computer and use it in GitHub Desktop.
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