Post Reply 
integer right triangles
10-15-2019, 12:40 AM
Post: #2
RE: integer right triangles
Start with the smaller number, a. You're now looking for pairs of numbers b, c, such that c^2 - b^2 = a^2. For the difference between two squares, there are two useful constraints.

First, you don't want to find the same triplet twice. That leads to the first constraint: b > a. (You don't need to consider b = a, since a^2 + a^2 = c^2 has no solutions in the positive integers, because sqrt(2) is irrational.)

Second, you don't want to search any further than you have to. The difference between two consecutive squares grows monotonically: (b+1)^2 - b^2 = 2*b - 1, so for a given a, you can stop searching when 2*b - 1 > a^2.

Further optimizations are possible, but with these two constraints, you can write a simple program that will enumerate all the Pythagorean triplets, and do it reasonably efficiently. I actually wrote this on my HP-41C back in the day, but that program was lost ages ago. Please share what you come up with!
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
integer right triangles - Lostinozone. - 10-14-2019, 08:29 PM
RE: integer right triangles - Thomas Okken - 10-15-2019 12:40 AM
RE: integer right triangles - vanLudwig - 10-15-2019, 02:34 AM
RE: integer right triangles - Joe Horn - 10-15-2019, 11:29 PM
RE: integer right triangles - SlideRule - 10-15-2019, 01:02 PM
RE: integer right triangles - Lostinozone. - 10-15-2019, 07:57 PM



User(s) browsing this thread: 1 Guest(s)