Count the Number of Triangles in Given Picture - Programmatic Solution With Examples

One of my friend sent me below image as puzzle to count the triangles. I started counting them and first got to 15, then again recounted and reached to 19.


But I was not sure whether I was right or not. So I thought of writing a simple program to find out the total number of triangles. I used below algorithm to find out the number of triangles.

  • Any triangle has three distinct points.
  • Any triangle consists of three different lines.

Now counting lines with points is easy, from below image we can easily see that it contains 7 lines.


Below is the program to find out the total number of triangles in these scenarios.

Below is the output of the above program.

So the total number of triangles is 24, well I missed a lot in counting them. But now I have an easy way to do it, I hope it will help someone too for these kind of problems.

By admin

Leave a Reply

%d bloggers like this: