Finished the pythagorean triangle circumferences

This commit is contained in:
2021-02-26 00:52:25 +01:00
parent 136d9e8bd2
commit 0b13772d44

29
39/main.py Normal file
View File

@@ -0,0 +1,29 @@
'''
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?
'''
import math
def main():
print("Hello this is Patrick")
ps = [0]*1000
for a in range(1, 1000):
for b in range(1, 1000-a):
c2 = a**2 + b**2
r = math.sqrt(c2)
if c2 == int(r + 0.5) ** 2:
r = int(r + 0.5)
if a + b + r <= 1000:
ps[a + b + r - 1] += 1
print(ps.index(max(ps)) + 1)
if __name__ == "__main__":
main()