- #1
- 2,168
- 193
- Homework Statement
- It turns out that 12 cm is the smallest length of wire that can be bent to form an integer sided right angle triangle in exactly one way, but there are many more examples.
12 cm: (3,4,5)
24 cm: (6,8,10)
30 cm: (5,12,13)
36 cm: (9,12,15)
40 cm: (8,15,17)
48 cm: (12,16,20)
In contrast, some lengths of wire, like 20 cm, cannot be bent to form an integer sided right angle triangle, and other lengths allow more than one solution to be found; for example, using 120 cm it is possible to form exactly three different integer sided right angle triangles.
120 cm: (30,40,50), (20,48,52), (24,45,51)
Given that L is the length of the wire, for how many values of L ≤ 1,500,000 can exactly one integer sided right angle triangle be formed?
- Relevant Equations
- none
The question simply asks primitive pythagorean triples ##(a,b,c)## such that ##S = a + b + c <15\times 10^{5}##
According to the rule ##gcd(m,n) = 1## and if ##m## is even ##n## must be odd or vice verse to create primitive pythagorean triples. So here is my code however it seems something is wrong.
Python:
import time
import math
start = time.perf_counter()
pythagorean_triples = {(3, 4, 5) : 12}
for m in range(0, 10**3, 2):
for n in range(1, m, 2):
if math.gcd(m, n) == 1:
pythagorean_triples.update( {(m**2 - n**2, 2*m*n, m**2 + n**2): 2*(m*(m+n))} )
for m in range(1, 10**3, 2):
for n in range(0, m, 2):
if math.gcd(m, n) == 1:
pythagorean_triples.update( {(m**2 - n**2, 2*m*n, m**2 + n**2): 2*(m*(m+n))} )
pythagorean_triples_copy = pythagorean_triples.copy()
for key, value in pythagorean_triples.items():
if value >= 15 * 10 ** 5:
del pythagorean_triples_copy[key]
print(len(pythagorean_triples_copy))
end = time.perf_counter()
print(end - start, "sec")
According to the rule ##gcd(m,n) = 1## and if ##m## is even ##n## must be odd or vice verse to create primitive pythagorean triples. So here is my code however it seems something is wrong.
Last edited: