| 12345678910111213141516171819202122232425262728 |
- {-
- 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.
- -}
- rev_list :: [Char] -> [Char]
- rev_list [] = []
- rev_list [x] = [x]
- rev_list (x:xs) = (rev_list xs) ++ [x]
- bigger :: Int -> Int -> Int
- bigger x y = if (x > y) then x else y
- is_palindrome :: Int -> Bool
- is_palindrome x = (xs == (rev_list xs)) where xs = show x
- solution' :: Int -> Int -> Int -> Int
- solution' x 1000 res = res
- solution' 1000 y res = solution' 100 (y + 1) res
- solution' x y res = solution' (x + 1) y $! (if (is_palindrome (x * y))
- then (bigger (x * y) res)
- else res)
- solution :: Int
- solution = solution' 100 100 0
- main :: IO ()
- main = putStrLn ("Solution: " ++ show solution)
|