euler/e004.py
Correl Roush 12c5dd7875 Documented each exercise, and placed executable code in a main() function.
git-svn-id: file:///srv/svn/euler@63 e5f4c3ec-3c0c-11df-b522-21efaa4426b5
2010-05-04 18:21:07 +00:00

20 lines
722 B
Python

"""Find the largest palindrome made from the product of two 3-digit numbers.
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 palindrome():
palindromes = {}
for i in range(999, 99, -1):
for ii in range(999,99, -1):
result = str(i * ii)
if result == result[::-1]:
palindromes[i * ii] = [i, ii]
p = sorted(palindromes.keys(), reverse=True)[0]
print 'Palindrome: {0}x{1}: {2}'.format(palindromes[p][0], palindromes[p][1], p)
def main():
palindrome()
if __name__ == '__main__':
main()