Add Haskell solutions for Problems 4, 5, 6, 7

This commit is contained in:
2024-04-01 15:19:09 +02:00
parent 327998ae0f
commit b6b10cdd12
4 changed files with 60 additions and 0 deletions

15
Haskell/p004.hs Normal file
View 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)