This is my attempt at the Problem Euler #4 in Haskell ("Find the largest palindrome made from the product of two 3-digit numbers.")
import Data.List isPalindrome :: Show a => a -> Bool isPalindrome n = l == reverse l where l = show n maxPalindrome :: (Integral a, Show a) => a maxPalindrome = maximum $ head . transpose $ allPalindrome <$> [999, 998 .. 1] where allPalindrome x = filter (isPalindrome) $ (x *) <$> [999, 998 .. x]
To my surprise I didn't see any such optimisation in the snippets I found (the head . transpose is there to only consider the highest of each pairs), which surprised me. However this is still running about 0.5 seconds which I find still slow?
Is there a way to make it run faster? I am aware of Project Euler #4 in Haskell however, my question is not about the algorithm I use but about its implementation.
Do you have any other recommendation about my code?
Thank you very much in advance