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.
List of numbers each of which is product of two 3-digit numbers:
But this list contains too many duplicated numbers like 100*101 and 101*100. So remove such duplications.
Using bultin reverse function to check whether a number is palindrome or not. reverse takes list and returns a list of reverse order. Thus number should be converted into list to be applied. There are show function in bulitin which convert any data type that implements Show typeclass into String which is synonym of [Char]. Fortunately any number type implements Show so we can apply numbers show function. Now we can check if a number is palindrome by converting number to string and then taking reverse of it and then comparing with original string.
Almost done.
Take maxmimum palindrome number from the above list using filter and maximum:
'problem solving > Project Euler in Haskell' 카테고리의 다른 글
ProjectEuler Problem 6 - Sum square difference (0) | 2014.12.08 |
---|---|
ProjectEuler Problem 5 - Smallest multiple (0) | 2014.12.04 |
ProjectEuler Problem 3 - Largest prime factor (0) | 2014.12.03 |
ProjectEuler Problem 2 - Even Fibonacci numbers (0) | 2014.12.01 |
ProjectEuler Problem 1 - Multiples of 3 and 5 (0) | 2014.12.01 |