In the continuing series of solving Project Euler problems with F#, here is problem 4 and my solution:
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.
- Create the set of all products of two 3-digit numbers.
- Filter the values that are palindromes.
- Find the max of the palindrome values.
open System let problem4 = let reverseNumber value = Convert.ToInt32(new string(Array.rev (value.ToString().ToCharArray()))) [for i in [100..999] do for j in [100..999] do yield i * j] |> Seq.filter (fun x -> x = reverseNumber(x)) |> Seq.max
Download the source code with unit tests.