"Палиндромное число читается одинаково в обе стороны Самый большой палиндром, составленный из произведения двух двузначных чисел, равен 9009 = 91 × 99.
Найдите самый большой палиндром, составленный из произведения двух. Трехзначные числа."
Вот к чему я пришел на данный момент:
Код: Выделить всё
ProductOfThree = []
ProductOfThreeSTR = []
PalindromicNumber = []
#This first for loop displays all the results possible from the product of two 3 digit Number
for k in range(100, 1000):
for j in range(k, 1000):
Result = k * j
ProductOfThree.append(Result)
#This second loop converts the list of number to a list of string
for i in ProductOfThree:
a = str(i)
ProductOfThreeSTR.append(a)
#The third loop compare the digit of each number of the list to find all the palindromic number of that list
for d in ProductOfThreeSTR:
if len(d) == 6:
if (d[0] == d[5]) and (d[1] == d[4]) and (d[2] == d[3]):
PalindromicNumber.append(d)
elif len(d) == 5:
if (d[0] == d[4]) and (d[1] == d[3]):
PalindromicNumber.append(d)
#And finally here the program display the largest number of the list, which contains only the palindromic numbers
Largest = PalindromicNumber[0]
for p in PalindromicNumber:
if Largest
Подробнее здесь: [url]https://stackoverflow.com/questions/41387007/project-euler-4-with-python-largest-palindrome-product[/url]
Мобильная версия