PE 0009: Special Pythagorean Triplet
A Pythagorean triplet is a set of three numbers
For example,
There exists exactly one Pythagorean triplet for which
Find the product
Brute Force Search
We are given two constraints to find three variables but we know the search space is bounded and reasonably small. We're searching for two numbers (a, b) which together must sum less than 1000 because a third must add with them to 1000 and we know all three numbers are greater than zero.
Since we can derive
for a in range(2, number):
for b in range(a+1, number):
c = number - a - b
c2 = a**2 + b**2
if c**2 == c2:
PythagoreanTriplet(a, b, c)
We can avoid any floating-point math by comparing
See Also
TODO
Exercises
TODO