So im writing a program which finds pythagorean triples. I need to find a way to test out every single combination i can have with three numbers, all of them being under say 500, with the constraint that the last number in the three is always greater than the two before it.
Heres what ive got so far.
The code you have given ne555, doesnt it just increment a by one after each iteration of the program? So it wouldnt actually combine all the possibilities of a,b and c.
You are right, one loop merely iterates through a list of values, but it also gives us the possibility to do something with each value.
You could have a different loop inside that loop, for b.
Inside the inner loop you will have a pair of (a,b), where a<=b. If you do adjust the boundaries of both loops correctly, then same pair will not occur more than once.
You can test that by printing every pair (for small upper limit).
If you do have a and b, then you can calculate the c; no need for third loop.
Hello @billy606, it seems you've started two threads for the same problem. Never mind, I just wanted to draw your attention to my post to the other thread here: