in reply to Re: Largest palindrome number for a 3 digit product of 2 numbers
in thread Largest palindrome number for a 3 digit product of 2 numbers

Thanks . So you are checking the condition if the Square of the Number is less than the current product found in the second statement of the last

  • Comment on Re^2: Largest palindrome number for a 3 digit product of 2 numbers

Replies are listed 'Best First'.
Re^3: Largest palindrome number for a 3 digit product of 2 numbers
by shmem (Chancellor) on Jul 06, 2017 at 08:55 UTC

    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'