Add solution for problem 60.

This commit is contained in:
Jesse D. McDonald 2015-09-02 20:06:18 -05:00
parent 7d015132e9
commit 6996016ccc
1 changed files with 24 additions and 0 deletions

24
Problem060.hs Normal file
View File

@ -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)