31 lines
826 B
Haskell
31 lines
826 B
Haskell
{-
|
|
https://projecteuler.net/problem=4
|
|
A palindromic number reads the same both ways.
|
|
The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99.
|
|
|
|
Find the largest palindrome made from the product of two 3-digit numbers.
|
|
-}
|
|
|
|
import Debug.Trace (trace)
|
|
|
|
twoDigitProducts :: [Integer]
|
|
twoDigitProducts = [ n*m | n <- [10..99], m <- [n..99] ]
|
|
|
|
threeDigitProducts :: [Integer]
|
|
threeDigitProducts = [ n*m | n <- [100..999], m <- [n..999] ]
|
|
|
|
isPalindrome :: Integer -> Bool
|
|
isPalindrome n = all (== True) $ zipWith (==) half half'
|
|
where
|
|
(half, half'') = splitAt l n'
|
|
half' = reverse half''
|
|
l = length n' `div` 2
|
|
n' = show n
|
|
-- n' = trace (show n) $ show n
|
|
|
|
solve :: Integer
|
|
solve = maximum $ filter isPalindrome threeDigitProducts
|
|
|
|
main :: IO ()
|
|
main = print solve
|