-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path39.py
32 lines (26 loc) · 910 Bytes
/
39.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
""" Project Euler Problem 39:
If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
{20,48,52}, {24,45,51}, {30,40,50}
For which value of p <= 1000, is the number of solutions maximised?
"""
"""
Thoughts:
* Pythagorean theorem!!
* a^2 + b^2 = c^2
* c always is the biggest
* I bet there are some side lengths that can be ignored, but I don't know the rules around it...
"""
import math
from util import *
most_number_of_solutions = 0
for p in range(1, 1000):
number_of_solutions = 0
for c in range(p/3,p):
for b in range(1, c):
a = p - b - c
if a > 0 and a*a + b*b == c*c:
number_of_solutions += 1
if most_number_of_solutions < number_of_solutions:
most_number_of_solutions = number_of_solutions
print str(p) + ' yielded a new most number_of_solutions: ' + str(most_number_of_solutions)
print 'Done'