02-09-2017, 05:42 AM
Criteria
The program PYTHA calculates a Pythagorean triple. A Pythagorean triple is a set of three positive integers A, B, and C that represent the lengths of a right triangle, with C being the hypotenuse. Hence, A^2 + B^2 = C^2.
Pythagorean triples can be generated with three arbitrary positive integers M, N, and K with the following criteria:
1. M > N
2. M and N are coprime. That is, gcd(M, N) = 1 (gcd, greatest common denominator)
A, B, and C are generated by:
A = K * (M^2 – N^2)
B = K * (2 * M * N)
C = K * (M^2 + N^2)
Source:
“Pythagorean Triple” Wikipedia. Last Modified February 7, 2017.
https://en.wikipedia.org/wiki/Pythagorean_triple
Accessed February 7, 2017
The program PYTHA calculates a Pythagorean triple. A Pythagorean triple is a set of three positive integers A, B, and C that represent the lengths of a right triangle, with C being the hypotenuse. Hence, A^2 + B^2 = C^2.
Pythagorean triples can be generated with three arbitrary positive integers M, N, and K with the following criteria:
1. M > N
2. M and N are coprime. That is, gcd(M, N) = 1 (gcd, greatest common denominator)
A, B, and C are generated by:
A = K * (M^2 – N^2)
B = K * (2 * M * N)
C = K * (M^2 + N^2)
Code:
EXPORT PYTHA(M,N,K)
BEGIN
// 2017-02-08 EWS
// Pythagorean Triangle
LOCAL A,B,C;
// checks (not for minimum)
M:=IP(M); N:=IP(N); K:=IP(K);
IF M≤0 OR N≤0 OR
gcd(M,N)≠1 OR M≤N THEN
RETURN "INVALID"; KILL;
END;
// calculations
A:=K*(M^2-N^2);
B:=K*(2*M*N);
C:=K*(M^2+N^2);
RETURN {A,B,C};
END;
Source:
“Pythagorean Triple” Wikipedia. Last Modified February 7, 2017.
https://en.wikipedia.org/wiki/Pythagorean_triple
Accessed February 7, 2017