A little shy on time today, with a combination of a suddenly changing work schedule due to unforseen circumstances and an unusual bout of exhaustion and nap taking. The result? A project Euler problem to fill the time!
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99.
Find the largest palindrome made from the product of two 3-digit numbers.
The resulting code I made to quickly solve it:
#! /usr/bin/python
def isPalindrome(num):
numStr = str(num)
for i in range(0, len(numStr)/2):
if numStr[len(numStr)-i-1] is not numStr[i]:
return False
return True
for i in range(999*999, 100*100, -1):
if isPalindrome(i):
for k in range(999, 100, -1):
if i%k == 0:
if len(str(i/k)) == 3:
print i
break;
The answer? 10201. Done and done. Hopefully tomorrow I can start a larger project I've been aching to work on.
No comments:
Post a Comment