Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by salva (Canon)
on Jul 06, 2017 at 07:52 UTC ( [id://1194349]=note: print w/replies, xml ) Need Help??


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

Multiplication is a commutative operation (a*b and b*a are the same quantity). That means that we can eliminate half of the operations making the inner J loop stop when $j becomes lesser than $i. You can see that explicit as the condition of the J loop.

Other trick used to trim the search space is taking into account that for natural numbers if a >= b then a*c >= b*c, so as soon as we found a $j that makes a palindrome we can stop the J loop.

Finally whatever becomes $prod <= $best we can also stop J; or even I if $j is still at 999.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1194349]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-26 08:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found