Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- 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 isPalindromic(n):
- if n < 0 or n != int(n):
- print("Negative numbers and numbers with comma cannot be palindromic numbers.")
- return None
- # Make the number string
- stringNumber = str(n)
- for i in range(int(len(stringNumber)/2)):
- if stringNumber[i] != stringNumber[len(stringNumber)-i-1]:
- return False
- return True
- # MAIN FUNCTION
- LIMITPOWER = 3
- maxNumber = -10000
- maxI = -100
- maxJ = -100
- for i in range(10**(LIMITPOWER-1), 10**LIMITPOWER):
- for j in range(10 ** (LIMITPOWER - 1), 10 ** LIMITPOWER):
- product = i * j
- if product > maxNumber and isPalindromic(product):
- # print(product)
- maxNumber = product
- maxI = i
- maxJ = j
- print("The largest palindromic number in [" + str((10**(LIMITPOWER-1))**2) + ", " + str((10**LIMITPOWER - 1)**2) + "] is: " + str(maxNumber) + " = " + str(maxI) + " * " + str(maxJ) + ".")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement