Project Euler 9 Understanding
This question says:
The Pythagorean triplet is a set of three natural numbers, abc, for which
a 2 + b 2 = c 2
For example, 3 2 + 4 2 = 9 + 16 = 25 = 5 2 .
There is exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
I'm not sure what he is trying to ask you. We try to find and then insert these numbers into ?a2 + b2 = c2
a + b + c = 1000
a source to share
These problems are often trivially solvable if you find the right understanding. The trick here is to use a little algebra before writing the loop. I'll give you one hint. Look at the formula for creating Pythagorean triplets. Can you write the sum of the side lengths in a useful way?
Like a lot of Euler project problems, it's all about finding a set of numbers that simultaneously fulfill multiple constraints.
In this case, the restrictions:
1) a ^ 2 + b ^ 2 = c ^ 2
2) a + b + c = 1000
In early questions, the solution can be as simple as nested loops that try every possible combination.
a source to share