Lesson goal: Finding Pythagorean Triples

Previous: Square roots and the Pythagorean Theorem | Home | Next: Algebra vs. computer

Most people have heard of the Pythagorean Theorem, which states that $c^2=a^2+b^2$, where $c$ is the hypotenuse of a right triangle, and $a$ and $b$ are the other two sides (or legs) of the right triangle.

Quick! Could you guess three numbers that satsify $c^2=a^2+b^2$? You might have the famous 3-4-5 right triangle memorized.

Here is a quick computer way of generating numbers that satisfy Pythagorean's Theorem. Or stated another way, numbers that would work just fine as side lengths for a right triangle.

Here's the way it works. Start by thinking of any two numbers. Then do three calculations with them:

  1. Compute their product, then double it.
  2. Square each, then subtract the two squares.
  3. Square each, then sum them.
The three results you get are sides that would form a correct right triangle! These three steps are called"Diophantus's Rules."

Now you try. Try to translate the recipe for x, y, and z as stated above, and fill your results in for the x=, y= and z= lines.

Type your code here:

See your results here:

For the x=, y= and z=, program in the formulas according to list items 1, 2, and 3 in the text above (i.e. let x be twice the produce of a and b). Run the code and generate your very own Pythagorean Triples! When you get your results, can you prove they satisfy the Pythagorean Theorem? Dismiss.
Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.