From 6996016ccc33e1ffe7f8c289b4d869d412003075 Mon Sep 17 00:00:00 2001 From: Jesse McDonald Date: Wed, 2 Sep 2015 20:06:18 -0500 Subject: [PATCH] Add solution for problem 60. --- Problem060.hs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Problem060.hs diff --git a/Problem060.hs b/Problem060.hs new file mode 100644 index 0000000..2c0b48b --- /dev/null +++ b/Problem060.hs @@ -0,0 +1,24 @@ +-- Find the lowest sum for a set of five primes for which any two primes +-- concatenate to produce another prime. + +import Euler +import Debug.Trace +import Data.Array.Unboxed ((!)) + +nDigits n = ceiling $ logBase 10 $ max 1 $ fromIntegral n +a ## b = (a * (10 ^ nDigits b)) + b + +main = print $ head $ do + a <- drop 4 primes + b <- takeWhile (< a) primes + guard $ all isPrime $ [(## b), (b ##)] <*> [a] + --traceM $ show (a,b) + c <- takeWhile (< b) primes + guard $ all isPrime $ [(## c), (c ##)] <*> [a,b] + --traceM $ show (a,b,c) + d <- takeWhile (< c) primes + guard $ all isPrime $ [(## d), (d ##)] <*> [a,b,c] + e <- takeWhile (< d) primes + guard $ all isPrime $ [(## e), (e ##)] <*> [a,b,c,d] + let xs = [a,b,c,d,e] + return (sum xs, xs)