Project Euler Problem 060
import Control.Monad import Data.Ord import Data.List primes :: [Integer] primes = 2:f [3] [3,5..] where f (x:xs) ys = ps ++ f (xs++ps) [z | z<-qs,z`rem`x/=0] where (ps,qs) = span (< x*x) ys isPrime :: Integer -> Bool isPrime nn = imp nn primes where imp n (p:ps) = if n< p*p then True else if n`rem`p==0 then False else imp n ps factor :: Integer -> [Integer] factor nn = factorimpl nn primes where factorimpl n pri@(p:xs) = if p*p>n then [n] else if n`rem` p == 0 then p:factorimpl (n `quot` p) pri else factorimpl n xs cche :: (Show a1, Show a) => a1 -> a -> Bool cche a b = isPrime (read(show a++show b)) && isPrime (read(show b++show a)) p60primes :: [Integer] p60primes = takeWhile (<10000) primes l :: [Integer] l=p60primes solve' :: [[Integer]] solve' = sortBy (comparing sum ) [[a,b,c,d,e] | a<-l,let m=next a l, b<-m,let n=next b m, c<-n,let o=next c n, d<-o,let p=next d o, e<-p] where next x lst= filter (cche x) $ dropWhile (<=x) lst p60 :: Integer p60 = sum (head solve') -- コンパイルして13sec -- 26033 main :: IO () main = print p60