Skip to content

Instantly share code, notes, and snippets.

@GallagherCommaJack
Last active August 29, 2015 13:57
Show Gist options
  • Save GallagherCommaJack/9457622 to your computer and use it in GitHub Desktop.
Save GallagherCommaJack/9457622 to your computer and use it in GitHub Desktop.
--Helper and Main
isPalindrome :: Eq a => [a] -> Bool
isPalindrome xs = reverse xs == xs
main = print num4 >> print num4'
--Naive Solution (still finishes in .122 seconds with -O2)
threeDigNums :: [Int]
threeDigNums = [1000,999..100]
num4 = maximum [(a,x,y) | x <- threeDigNums, y <- threeDigNums, let a = x*y, isPalindrome (show a)]
-- Less Naive Solution, takes .05-.06 seconds without any other optimizations
threeDigNums' :: [Int]
threeDigNums' = [1000,999..900]
num4' = maximum [(a,x,y) | x <- threeDigNums', y <- threeDigNums', let a = x*y, isPalindrome (show a)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment