All programs are contained in a single file here.
Program: RMptriples.z80
I was motivated to write this after using a Pythagorean Triple - 21, 220, 221 - in the 3D version of the Lagrange Points program to perform a small rotation.
I discovered these can be generated by the so-called Euclid's Formula, even though the method seems to have been known to the Babylonians at least 1500 years before the time of Euclid (see e.g. info here about clay tablet Plimpton 322).
To generate triples (a, b, c), the formula says:
a = m*m - n*n; b = 2*m*n; c = m*m +n*n
where m and n:
are positive integers
m > n
one of m, n is even
one of m, n is odd
m, n are co-prime
To ensure this last condition, I used the more efficient form of Euclids's Algorithm from the Highest Common Factor program.
Conditions 3, 4 and 5 ensure the triples are primitive, i.e. they cannot be reduced to a simpler form, as e.g. triple (6, 8, 10) can be.
In the program, m takes integer values from 2 to 10. The last number can be edited of course to increase the number of triples. n takes values from 1 to m-1.
The triples are displayed in the following order: short side, longer side, hypotenuse. At some point it would be good to sort the output, e.g. by hypotenuse. However, I can see a problem: the list will not be complete for the range of numbers produced. This can be seen from the above output where e.g. a triple with c=113 is generated before one with c=85. The program stops with m=10, so could we have missed some with c smaller than the largest of 181 shown? The answer is yes - by making m=11, 3 of the extra 5 triples generated have values of c less than 181.