Terrapin Resources

Triangles

by Stan Burech

The Problem

It takes 3 non-parallel lines to make a triangle. If there are more than 3 non-parallel lines, how many triangles do they make?

Illustration

To visualize the problem use between 3 and 7 lines (more than 7 becomes too cumbersome to draw), run the procedure Triangles? :Lines inserting the number of lines you want to see (example: Triangles 7) and try counting them yourself.

TERRAPIN LOGO DOES THE HEAVY LIFTING: Now let Terrapin Logo count the triangles for you by running TriangleCount :Lines.

The Mathematics

This problem comes from a branch of mathematics called combinatorics. Combinatorics uses factorials. There is another procedure in the Terrapin Logo library employing factorials.

Here is the reasoning for solving the number of triangles created by seven non-parallel lines. There are 7 lines, so one line can be one side of the triangle. The second side of the triangle can be from the six remaining lines and the third choice from the remaining five lines. The total number of ways you can choose the sides of the triangle is 7x6x5. but you don’t want to say there are six triangles when there is really only one simply because you can use the same three sides to create the same triangle in six different orders. So, divide out this redundancy and the answer becomes (7x6x5) / 6 = 35. And the general formula for any number of lines, therefore, is C (N,R) = N! / (N - R)! R! where N is the number of lines and R is the number of choices out of the seven lines, or 3 for the making the triangles. For 7 lines:

C(N,R) = 7!/ (7-3)! x 3! = 5040/ 24 x 6 = 5 -1) = 5040/144 = 35.

You now should be able to understand why, if you have a bag of six sticks of six different colors, and you pull out three, you have 20 different color combinations possible: 6 x 5 x 4 / 6. (Demonstrating the failure of most people to understand the basics of combinatorics and other rational behaviors won Daniel Kahneman a Nobel Prize in Economics.)

HAVE FUN WHILE TERRAPIN LOGO DOES THE WORK: Run 51976 non-parallel lines in the procedure TriangleCount :Lines (TriangleCount 51976) and see how fast Terrapin Logo counts the number of triangles. (Answer: 23,400,882,905,400 triangles). Now work out the math for 9 non-parallel lines:

(9!/(9-3)!3! = 362,880/6!3! = 362,880/720x6 = 362,880/ 4320 = 84)

and then check it against the procedure TriangleCount :Lines

HAVING TROUBLE SEEING THE TRIANGLES? Calculate how many triangles there should be with 5 non-parallel lines:

5!/(5-3)! x 3! = 120/(2 x 6) = 120/12 = 10

or just run the procedure TriangleCount 5.

To see the 10 triangles formed from 5 non-parallel lines, run the procedure ColorTriangles5 (5 non-parallel lines were chosen to illustrate how to find the triangles because less than five becomes trite and more than five becomes too messy).


Procedure ColorTriangles5
Description How many triangles do you see of N non-parallel lines?
Level Intermediate
Tags Math, Combinatorics