Project Euler in F#!
Project Euler: Problem 4
Find the largest palindrome made from the product of two 3-digit numbers.
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
I seriously don't like how I came about with this solution and I think to myself that it is the worst of them out there. I suppose not knowing every single operator or trick in F# results in coding like this.
The idea behind this was that once I found a product, I needed to test if it was a palindrome. I even thought about trying out regular expressions but I felt more comfortable with this approach although it is a bit more verbose than I had hoped for. So I converted each product to a string and further broke the String down to a character array since I could then use the Array.rev function to reverse the members of an array.
So the formula here is to calculate the produce, convert it to a string, get the reverse of the string and compare the two for equality. Note that F# has built in support for reverse for loops using the downto keyword. Also, the problem asked specifically for 3-digit computations, so I figured out that the best best was the try all products in the range of 900-999 first, then go lower if need be.