Add Haskell solutions for Problems 4, 5, 6, 7
This commit is contained in:
15
Haskell/p004.hs
Normal file
15
Haskell/p004.hs
Normal file
@ -0,0 +1,15 @@
|
||||
-- A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
|
||||
--
|
||||
-- Find the largest palindrome made from the product of two 3-digit numbers.
|
||||
|
||||
isPalindrome :: Integer -> Bool
|
||||
isPalindrome n = show n == (reverse $ show n)
|
||||
|
||||
maxPalindrome :: Integer
|
||||
maxPalindrome =
|
||||
maximum $ filter isPalindrome [ x * y | x <- [100..999], y <- [100..999] ]
|
||||
|
||||
main = do
|
||||
let result = maxPalindrome
|
||||
putStrLn $ "Project Euler, Problem 4\n"
|
||||
++ "Answer: " ++ (show result)
|
Reference in New Issue
Block a user