Project Euler Problem 004
import Data.List import Control.Applicative ispalin :: Eq a => [a] -> Bool ispalin str = str == reverse str from :: Integer from=999 list :: [(Integer, Integer)] list = [(x,y)|x<-[1..from],y<-[1..from]] palinlist :: [(Integer, Integer)] palinlist = filter (\(x,y) -> ispalin $ show (x*y)) list sortedlist :: [(Integer, Integer)] sortedlist = sortBy (\(l,r) (ll,rr) -> compare (l*r) (ll*rr)) palinlist answer :: Integer answer = (liftA2 (*) fst snd) $ last sortedlist -- 906609 main :: IO () main = print answer -- 別解 d :: [Integer] d = [100..999] m :: (Integer, Integer, Integer) m = maximum [(t,a,b) | a<-d,b<-d,let t=a*b,reverse(show t)==show t] --(906609,993,913)