-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem39.py
51 lines (36 loc) · 1.15 KB
/
problem39.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import time
import math
def calculate_time(func):
def inner1(*args, **kwargs):
begin = time.time()
returned_value = func(*args, **kwargs)
end = time.time()
print("Total time taken in : ", func.__name__, end - begin)
return returned_value
return inner1
#########################################################################3
def is_triangle(a, b, c):
return(a+b>c and b+c>a and a+c>b)
def triangle_from_perimeter(p):
solutions = []
for i in range(1, int(p/3)):
if (p**2 -2*p*i)%(2*p-2*i) == 0:
a = int((p**2 -2*p*i)/(2*p-2*i))
c = int(math.sqrt(a**2 + i**2))
if is_triangle(a, i, c):
solutions.append({a, i, c})
return solutions
#########################################################################3
@calculate_time
def main():
max39 = 0
index = 0
for p in range (1, 1001):
temp = triangle_from_perimeter(p)
if max39 < len(temp):
max39 = len(temp)
index = p
print(index)
return 0
if __name__ == "__main__":
main()