1
0
Fork 0

Problem 60

This commit is contained in:
Jonathan Chan 2017-05-15 23:08:33 -07:00
parent 9ffa46156f
commit 53bca2b2d6
4 changed files with 43 additions and 0 deletions

BIN
60 Executable file

Binary file not shown.

BIN
60.hi Normal file

Binary file not shown.

43
60.hs Normal file
View File

@ -0,0 +1,43 @@
import Data.List
upper = 10000
isPrime :: Integer -> Bool
isPrime x = null [k | k <- [2..x-1], k * k <= x, x `mod` k == 0]
primes = [x | x <- [2..upper], isPrime x]
isPrimeNew :: Integer -> Bool
isPrimeNew x
| x <= upper = elem x primes
| otherwise = isPrime x
order :: (Integer, Integer, Integer, Integer, Integer) -> (Integer, Integer, Integer, Integer, Integer) -> Ordering
order (a1, b1, c1, d1, e1) (a2, b2, c2, d2, e2) =
compare (a1 + b1 + c1 + d1 + e1) (a2 + b2 + c2 + d2 + e2)
combosArePrime :: Integer -> Integer -> Integer -> Integer -> Integer -> Bool
combosArePrime a b c d e =
isPrimeNew (read (show a ++ show b)) &&
isPrimeNew (read (show b ++ show a)) &&
isPrimeNew (read (show a ++ show c)) &&
isPrimeNew (read (show c ++ show a)) &&
isPrimeNew (read (show b ++ show c)) &&
isPrimeNew (read (show c ++ show b)) &&
isPrimeNew (read (show a ++ show d)) &&
isPrimeNew (read (show d ++ show a)) &&
isPrimeNew (read (show b ++ show d)) &&
isPrimeNew (read (show d ++ show b)) &&
isPrimeNew (read (show c ++ show d)) &&
isPrimeNew (read (show a ++ show e)) &&
isPrimeNew (read (show e ++ show a)) &&
isPrimeNew (read (show b ++ show e)) &&
isPrimeNew (read (show e ++ show b)) &&
isPrimeNew (read (show c ++ show e)) &&
isPrimeNew (read (show d ++ show e)) &&
isPrimeNew (read (show e ++ show e))
quints = sortBy order [(a, b, c, d, e) | a <- primes, b <- primes, c <- primes, d <- primes, e <- primes,
a < b, b < c, c < d, d < e, combosArePrime a b c d e]
main = print primes

BIN
60.o Normal file

Binary file not shown.