-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem4.py
More file actions
31 lines (24 loc) · 761 Bytes
/
problem4.py
File metadata and controls
31 lines (24 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/python
from tools.timeit import timeit
from tools.general import isPalindrome
problem = """Find the largest palindrome made from the product of two 3-digit numbers."""
@timeit
def process():
solutions = []
maxmin = 0
N = 1000
for x in xrange(N, N/10 - 1 , -1):
for y in xrange(x, N/10 - 1, -1):
value = x*y
if isPalindrome(value):
solutions.append((value, x, y))
if y > maxmin:
maxmin = y
break
if x <= maxmin:
break
value = max(solutions)
return value
etime, solution = process()
print "Problem :\n%s\n\n\nSolution :\n%s" % (problem, solution)
print "\nRunning time : %10.6f seconds" % (etime)