You will generate primitive Pythagorean triples from the formula and check them against a direct search, then find every triple with a given leg.
The idea. For , coprime and of opposite parity, the formula gives . A search tries every pair of legs and tests whether is a perfect square.
Your tasks.
primitive_by_formula(limit). Return the set of triples with and below limit, from the formula.primitive_by_search(limit). Return the same set by a search over legs , keeping only triples with .triples_with_leg(a). Return the sorted list of all triples (primitive or not) with the leg , as pairs .Run your code once to unlock the worked solution.
Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…