Problem 60 alt attempt
This commit is contained in:
parent
0b072a1efe
commit
768237c43e
31
60_alt.hs
31
60_alt.hs
|
@ -1,11 +1,12 @@
|
||||||
|
{-# LANGUAGE BangPatterns #-}
|
||||||
import Data.List
|
import Data.List
|
||||||
|
|
||||||
upper = 10000
|
upper = 8000
|
||||||
|
|
||||||
isPrime :: Int -> Bool
|
isPrime :: Int -> Bool
|
||||||
isPrime x = null [k | k <- [2..x-1], k * k <= x, x `mod` k == 0]
|
isPrime x = null [k | k <- [2..x-1], k * k <= x, x `mod` k == 0]
|
||||||
|
|
||||||
primes = [x | x <- [2..upper], isPrime x]
|
!primes = [x | x <- [2..upper], isPrime x]
|
||||||
|
|
||||||
isPrimeNew :: Int -> Bool
|
isPrimeNew :: Int -> Bool
|
||||||
isPrimeNew x
|
isPrimeNew x
|
||||||
|
@ -17,4 +18,28 @@ isPrimePair a b = isPrime(read(show a ++ show b)) && isPrime(read(show b ++ show
|
||||||
|
|
||||||
primePairs = [(a, b) | a <- primes, b <- primes, a < b, isPrimePair a b]
|
primePairs = [(a, b) | a <- primes, b <- primes, a < b, isPrimePair a b]
|
||||||
|
|
||||||
main = print primePairs
|
primeSets = [(a, b, c, d, e) | a <- primes,
|
||||||
|
b <- primes,
|
||||||
|
a < b,
|
||||||
|
isPrimePair b a,
|
||||||
|
|
||||||
|
c <- primes,
|
||||||
|
b < c,
|
||||||
|
isPrimePair c a,
|
||||||
|
isPrimePair c b,
|
||||||
|
|
||||||
|
d <- primes,
|
||||||
|
c < d,
|
||||||
|
isPrimePair d a,
|
||||||
|
isPrimePair d b,
|
||||||
|
isPrimePair d c,
|
||||||
|
|
||||||
|
e <- primes,
|
||||||
|
d < e,
|
||||||
|
isPrimePair e a,
|
||||||
|
isPrimePair e b,
|
||||||
|
isPrimePair e c,
|
||||||
|
isPrimePair e d]
|
||||||
|
|
||||||
|
|
||||||
|
main = print $ head primeSets
|
||||||
|
|
Loading…
Reference in New Issue