Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
a = []
b = []
for x in range (101, 999):
    for y in range (101, 199):
        z = x * y
        a.append(z)
def reverse(n):
    n = str(n)
    if n == n[::-1]:
        n = int(n)
        b.append(n)
    return b

for number in a:
    reverse(number)

print max(b)


My result is 180181 but it should be 906609.

The original problem was:

"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."
Posted
Updated 19-Nov-14 5:06am
v2

1 solution

I would keep it simple:
Python
m = 0
for x in range (100, 999):
  for y in range (100, 999):
    z = x*y
    n = str(z)
    if n == n[::-1]:
      if  m < z:
        m = z

print(m)
 
Share this answer
 
Comments
Member 11243554 19-Nov-14 12:07pm    
Thanks for the solution but I was more looking for the problem in my code i.e. why my code ain't working? What's wrong with it?
CPallini 19-Nov-14 13:25pm    
Your code doesn't work because the upper limit of the inner for loop is wrong (it should be 999).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900