-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.py
More file actions
16 lines (14 loc) · 779 Bytes
/
4.py
File metadata and controls
16 lines (14 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
###############################################################################
# Project Euler Problem 4
# Largest palindrome product
# 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 largest_palindrome_product(digits):
largest = 0
for i in range((10 ** digits) - 1, (10 ** (digits - 1)) - 1, -1):
for j in range((10 ** digits) - 1, (10 ** (digits - 1)) - 1, -1):
if str(i * j)[::-1] == str(i * j):
largest = max(i * j, largest)
return largest
print(largest_palindrome_product(3))