I'm trying to find the largest palindrome that is the product of two 3-digit numbers. My guest is that the palindrome will have the form abccba, so I will just loop over each digit and stop at the largest number that is the product of two 3-digit numbers.
This piece of code
def hasLargeDivisors(n):
"""
Function to determine if a number has two divisors
greater than 99
"""
d = 999
while n / d > 99 and n / d < 999 and d > 99:
if n % d is 0:
return True
d-=1
return False
def compisitePalindrome():
"""
Function to find the largest palindrome
that is the product of 2 three-digit numbers
"""
for a in reversed(xrange(1, 9)):
for b in reversed(xrange(0, 9)):
for c in reversed(xrange(0, 9)):
num = a*100001 + b*10010 + c*1100
if hasLargeDivisors(num):
return num
return 0
produces 888888 = 962 * 924, which is incorrect.
This code
def hasLargeDivisors(n):
"""
Function to determine if a number has two divisors
greater than 99
"""
d = 999
while n / d > 99 and n / d < 999 and d > 99:
if n % d is 0:
return True
d-=1
return False
def compisitePalindrome():
"""
Function to find the largest palindrome
that is the product of 2 three-digit numbers
"""
a = 9
for b in reversed(xrange(0, 9)):
for c in reversed(xrange(0, 9)):
num = a*100001 + b*10010 + c*1100
if hasLargeDivisors(num):
return num
return 0
produces 906609 = 993 * 913, which is correct.
I don't know where I went wrong.
11. So, start with highest multiple of11, which is a multiple of two 3 digits numbers, and then step using-11, inxrangeand check whether the number is palindrome or not.