E004 A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.
Find the largest palindrome made from the product of two 3-digit numbers.
水仙花数是从左向右和从右向左读都相同的自然数。求两个三位数的乘积中最大的水仙花数。
def problem4():
min, max = 100, 999
def isPalindromic(num):
if num<=10:
return False
digits = list(str(num))
revdigs = list(str(num))
revdigs.reverse()
return digits==revdigs
x = y = avg = max
while avg>=min:
num = x*y
if isPalindromic(num):
return x,y,num
elif x<=min or y>=max:
avg -= 0.5
x = int(avg)
y = int(avg+0.5)
else:
x -= 1
y += 1