(42S) List Pythagorean Triples - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (42S) List Pythagorean Triples (/thread-13812.html) |
(42S) List Pythagorean Triples - ijabbott - 10-16-2019 07:33 PM This program lists Pythagorean triples, (natural numbers \(a, b, c\), such that \(a^2 + b^2 = c^2\)) as alpha strings on the display, starting with "3,4,5". They are not listed in any monotonic order, but successive hypotenuses are listed in a reverse sawtooth pattern. The triples (\(a,b,c\)) are generated from pairs of natural numbers \(m\), \(n\), such that \(m > n > 0\), and \(m\) and \(n\) are co-prime and not both odd (to filter out non-primitive triples such as 6,8,10), using Euclid's formula: \[a = m^2 - n^2, b = 2mn, c = m^2 + n^2\] The program uses registers R00 and R01 to store \(m\) and \(n\), and uses the ALPHA register to show the triple "\(a,b,c\)" (if \(a < b\)), or "\(b,a,c\)" (if \(a > b\)). The program stops after each triple is displayed. Press R/S to continue. Code: 00 { 90-Byte Prgm } |