#Project Euler Problem 4
import time
start = time.time()
global bigO
bigO = 0
n=999*999
pal=0
def is_pal(n):
nstr = str(n)
if nstr == nstr[::-1]:
#print nstr + " is a palindrome."
return 1
else:
return 0
def has_3digit_factors(n):
global bigO
for i in range(999,100,-1):
bigO += 1
if n % i == 0:
if len(str(n/i)) == 3:
#print str(n) + " is composed of two 3-digit factors: " + str(i) + ", " + str(n/i)
return n
return 0
while pal == 0:
bigO += 1
if n%11 == 0 and is_pal(n):
pal = has_3digit_factors(n)
n -= 1
print "The largest palindromic number that is the product of two 3 digit numbers is: ",pal
print "Iterations: ", bigO
print "Total elapsed time: " + str((time.time()-start)*1000) + " milliseconds."