Last active
August 29, 2015 13:57
-
-
Save GallagherCommaJack/9457622 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--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