Euler 4
So the other night I was a bit bored and decided to do something to pass the time. I first came across Project Euler a while ago, but had never gone further than problem #1. Boredom is a great motivator and I went through problems #2 thru #9 last night and I decided to post my solutions in search of better ones. Feel free to comment with your suggestions.
Project Euler’s Problem #4 statement is —
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.
And here’s the solution.
def int_to_list(number):
return map(int, str(number))
def is_palindrome(number):
local_list = int_to_list(number)
return local_list == list(reversed(local_list))
pal = 0
if __name__ == "__main__":
for i in range(100,1000):
for j in range(100,1000):
if is_palindrome(i * j):
print "%d * %d = %d"%(i, j, i*j)
if i * j > pal:
pal = i * j
print pal