Yes. If the square of the greater operand is smaller than the highest palindrome found, further rundown of either factor can be stopped. There is no higher number to be found.
My algorithm differs from salvas solution, which probes the highest factors for a valid product, while mine runs down one factor to its lowest value. For some amount of digits it turns out to be faster than salva's, for others it is much, much slower (e.g. 9 digits).
update: Another approach would be:
- Starting from the square of the highest number, construct the next lower palindrome number
- factorize that number
- check for any cobination of factors whether their product has the amount of digits wanted
- check if the remaining factors product also has the amount of digits wanted
- If so, stop there. Highest palindrome found.
I guess that for a large amount of digits this might be the fastest way.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
| [reply] |