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.
- #isPal algorithm from MIT 6.00x course notes
- #Analysis
- #A brutish way to find the largest palindrome product of two 3-digit numbers is by searching odd factors downwards #from 999. We test each product as a palindrome and save it. Our search ends when the next product falls below the #largest palindrome found.
- #The two factors are printed along with their product.
- def isPal(s):
- if len(s) <= 1:
- return True
- else:
- return s[0] == s[-1] and isPal(s[1:-1])
- pmax = 0
- for i in range(999,100,-2):
- for j in range(i,100,-2):
- p = i*j
- if p < pmax: break
- if isPal(p): x,y,pmax = i,j,p
- print x,'x',y,'=',pmax
Advertisement
Add Comment
Please, Sign In to add comment