I am doing a python problem and I need to find the largest palindrome made from the product of two 3-digit numbers. So, how would I get all possible combinations?
I imagine it is multiplying all combinations of 100 to 999 but am a bit stuck on how to do this. I hope this makes sense.
def genYieldThreeValues(stop):
j = 999
while stop >99 and j > 99:
multiples = str(stop * j)
front = multiples[:3] # get front three numbers
back = multiples[-3:] # get last three numbers
stop-=1
j-=1
yield [front,back,multiples] # yield a list with first three, last three and all numbers
def highestPalindrome(n):
for x in genYieldThreeValues(n):
if x[1] ==x[0][::-1]: # compare first three and last three digits reversed
return x[2] # if they match return value
print(highestPalindrome(999))