Project Euler #4
This commit is contained in:
21
src/projectEuler/question4.hs
Normal file
21
src/projectEuler/question4.hs
Normal file
@@ -0,0 +1,21 @@
|
||||
-- https://projecteuler.net/problem=4
|
||||
|
||||
import Debug.Trace (trace)
|
||||
|
||||
twoDigitProducts :: [Integer]
|
||||
twoDigitProducts = [ n*m | n <- [10..99], m <- [n..99] ]
|
||||
|
||||
isPalindrome :: Integer -> Bool
|
||||
isPalindrome n = all (== True) $ zipWith (==) half half'
|
||||
where
|
||||
(half, half'') = splitAt h n'
|
||||
half' = reverse half''
|
||||
h = length n' `div` 2
|
||||
n' = show n
|
||||
-- n' = trace (show n) $ show n
|
||||
|
||||
solve :: Integer
|
||||
solve = maximum $ filter isPalindrome twoDigitProducts
|
||||
|
||||
main :: IO ()
|
||||
main = print solve
|
||||
Reference in New Issue
Block a user