Project Euler Problem 4 - Python
This is the third Project Euler problem solved using Python.
If you are running this on a computer with older hardware, do not freak out if a result is not immediately returned. There are quite a few calculations this program has to make. That said, on my steady yet sturdy PIII, it takes about six to seven seconds for this to complete.
# euler4.py # # 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 palindromic(nbr): s = str(nbr) n = len(s) for i in range(len(s)//2): if s[i] != s[n - i - 1]: return False return True biggest = 0 m1 = 0 m2 = 0 for i in range(100,1000): for j in range(100,1000): x = i * j if palindromic(x): if (x > biggest): m1 = i m2 = j biggest = x print "%d times %d equals the biggest palindromic number: %d." % (m1, m2, biggest)