diff --git a/src/projectEuler/question4.hs b/src/projectEuler/question4.hs index d5ba537..c27fe1c 100644 --- a/src/projectEuler/question4.hs +++ b/src/projectEuler/question4.hs @@ -1,10 +1,19 @@ --- https://projecteuler.net/problem=4 +{- +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 @@ -15,7 +24,7 @@ isPalindrome n = all (== True) $ zipWith (==) half half' -- n' = trace (show n) $ show n solve :: Integer -solve = maximum $ filter isPalindrome twoDigitProducts +solve = maximum $ filter isPalindrome threeDigitProducts main :: IO () main = print solve