You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
631 B
28 lines
631 B
2 years ago
|
three_digit_nums = [i for i in range(100, 999)]
|
||
|
|
||
|
|
||
|
def is_palindrome(n):
|
||
|
norm = str(n)
|
||
|
even = len(norm) % 2 == 0
|
||
|
if even:
|
||
|
half = norm[:int(len(norm)/2)]
|
||
|
other_half = [c for c in norm[int(len(norm)/2):]]
|
||
|
other_half.reverse()
|
||
|
for i, c in enumerate(half):
|
||
|
if c != other_half[i]:
|
||
|
return False
|
||
|
else:
|
||
|
return True
|
||
|
else:
|
||
|
return False
|
||
|
|
||
|
products = []
|
||
|
|
||
|
for i in three_digit_nums:
|
||
|
for j in three_digit_nums:
|
||
|
product = i*j
|
||
|
if is_palindrome(product):
|
||
|
products.append(product)
|
||
|
|
||
|
print(max(products))
|