Add solution for problem 60.
This commit is contained in:
parent
7d015132e9
commit
6996016ccc
|
|
@ -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)
|
||||||
Loading…
Reference in New Issue