Project Euler 4: (Iron)Python
Posted
by Ben Griswold
on Johnny Coder
See other posts from Johnny Coder
or by Ben Griswold
Published on Mon, 13 Sep 2010 02:44:20 +0000
Indexed on
2010/12/06
16:59 UTC
Read the original article
Hit count: 344
In my attempt to learn (Iron)Python out in the open, here’s my solution for Project Euler Problem 4.
As always, any feedback is welcome.
# Euler 4 # http://projecteuler.net/index.php?section=problems&id=4 # 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 x 99. # Find the largest palindrome made from the product of # two 3-digit numbers. import time start = time.time() def isPalindrome(s): return s == s[::-1] max = 0 for i in xrange(100, 999): for j in xrange(i, 999): n = i * j; if (isPalindrome(str(n))): if (n > max): max = n print max print "Elapsed Time:", (time.time() - start) * 1000, "millisecs" a=raw_input('Press return to continue')
© Johnny Coder or respective owner