-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem9.py
More file actions
31 lines (25 loc) · 802 Bytes
/
problem9.py
File metadata and controls
31 lines (25 loc) · 802 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
31
#!/usr/bin/python
from tools.timeit import timeit
problem = """A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
a2 + b2 = c2
For example, 32 + 42 = 9 + 16 = 25 = 52.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc."""
@timeit
def process():
value = None
for a in xrange(500, 0, -1):
for b in xrange(a-1, 0, -1):
c = 1000 - a - b
aa = a*a
bb = b*b
cc = c*c
if aa == (bb + cc):
value = (a*b*c)
break
if value is not None:
break
return value
etime, solution = process()
print "Problem :\n%s\n\n\nSolution : %s" % (problem, solution)
print "\nRunning time : %10.6f seconds" % (etime)