4: Largest palindrome product#
Description
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.
Your Solution#
Lunch this notebook and try to create your own solution!
Tip: look for the launch button (🚀) in the top right corner!
def problem4(N): # N = number of digits
# Try your solution here
return solution
# Testing:
unittest.main(argv=[''], verbosity=2,exit=False)
# Printing Project Euler Solution
# print(problem4(3))
My solution#
Spoiler Alert!!
See my solution bellow
# Note: this solution does not scale well! Keep N<=4
def problem4(N):
palindromic = 0
for i in range(10**N-1, 10**(N-1)-1, -1):
for j in range(10**N-1, i-1, -1):
product = i*j
if str(product) == str(product)[::-1]:
if product > palindromic:
palindromic = product
break
return palindromic
# Testing
unittest.main(argv=[''], verbosity=2,exit=False)
The largest palindrome made from the product of two 3-digit numbers is
# Printing Project Euler Solution
problem4(3)
906609