https://projecteuler.net/problem=4
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.
In [3]:
x = 1000
my_list = []
reverse = []
palin = []
for i in range(x): # this will give you i values from 0 to 999
for j in range(x): # this will also give you values from 0 to 999
my_list.append(list(str(i*j))) #this takes all the products of all the values from 0-999 and with 0-999 and puts the product in a list, and then puts all the lists in a list
reverse.append((list(str(i*j)))[::-1]) # this does the same as the above, but appends the products in "steps of -1", meaning the product is listed backwards then those lists are appeneded to the "reverse" list
for i in range(len(my_list)):
if my_list[i] == reverse[i]: # if the products are the same in both list (forwards and backwards)
palin.append("".join(my_list[i])) #then the lists in a list are joined into a single element lists in a list
for i in range(len(palin)):
palin[i] = int(palin[i]) # the values of the single element lists are turned into a list of the values
print(max(palin)) # then the max value of the list is taken
In [ ]:
# This cell will be used for grading, leave it at the end of the notebook.