pythagorean triples exercise
Terry Reedy
tjreedy at udel.edu
Sat Oct 23 15:28:55 EDT 2010
On 10/23/2010 3:34 AM, Lawrence D'Oliveiro wrote:
> In message<8idui6F213U1 at mid.individual.net>, Peter Pearson wrote:
>
>> Is it important to let "a" range all the way up to b, instead of
>> stopping at b-1? (tongue in cheek)
>
> Makes no difference. :)
The difference is that before one writes the restricted range, one must
stop and think of the proof that a==b is not possible for a pythagorean
triple a,b,c. (If a==b, c==sqrt(2)*a and the irrationality of sqrt(2)
implies that c is also irrational and therefore not integral). The OP
asked for how to translate the problem description into two loops, one
nested inside the other, and I gave the simplest, obviously correct,
brute-force search answer.
If the problem specification had asked for primitive triples (no common
factors), an additional filter would be required.
Another respondent referred, I believe, to Euclid's formula
https://secure.wikimedia.org/wikipedia/en/wiki/Pythagorean_triple
However, it is not well suited to the problem specified.
--
Terry Jan Reedy
More information about the Python-list
mailing list