Skip to content

Instantly share code, notes, and snippets.

@kenprice
Created January 1, 2019 23:17
Show Gist options
  • Save kenprice/d171bd9ff61b2ff1204369b722a09d23 to your computer and use it in GitHub Desktop.
Save kenprice/d171bd9ff61b2ff1204369b722a09d23 to your computer and use it in GitHub Desktop.
Project Euler Problem 4
import Data.List
products :: [Int]
products = reverse (Data.List.sort [x*y | x<-[100..999], y<-[100..999]])
isPalindrome :: Int -> Bool
isPalindrome x = (read (reverse (show x)) :: Int) == x
getLargestPalindrome :: [Int] -> Int
getLargestPalindrome xs =
if isPalindrome (head xs)
then (head xs)
else getLargestPalindrome(tail xs)
main :: IO()
main = putStrLn (show (getLargestPalindrome products))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment