1
0
Fork 0

Problem 60 (alternative attempt with prime pairs)

This commit is contained in:
Jonathan Chan 2017-05-17 23:40:44 -07:00
parent 53bca2b2d6
commit ec4d03be17
4 changed files with 20 additions and 0 deletions

BIN
60_alt Executable file

Binary file not shown.

BIN
60_alt.hi Normal file

Binary file not shown.

20
60_alt.hs Normal file
View File

@ -0,0 +1,20 @@
import Data.List
upper = 10000
isPrime :: Int -> Bool
isPrime x = null [k | k <- [2..x-1], k * k <= x, x `mod` k == 0]
primes = [x | x <- [2..upper], isPrime x]
isPrimeNew :: Int -> Bool
isPrimeNew x
| x <= upper = elem x primes
| otherwise = isPrime x
isPrimePair :: Int -> Int -> Bool
isPrimePair a b = isPrime(read(show a ++ show b)) && isPrime(read(show b ++ show a))
primePairs = [(a, b) | a <- primes, b <- primes, a < b, isPrimePair a b]
main = print primePairs

BIN
60_alt.o Normal file

Binary file not shown.