An elegant LED illustration of a mathematical identity

## Step 1: Final Result

Here is the demo. The flashing LEDs are used to illustrate the mathematical identity visually.

## Step 2: Math

For every two green dots on the bottom row, there is always a unique red dot in the triangle above that corresponds to them. That red dot is the tip of an equilateral triangle with the base specified by the green dots.

Therefore, the number of ways to choose 2 green dots out of n green dots is equal to the sum of the red dots, 1 +2 + 3 + … + (n-1).

This observation was originally made by Loren C. Larson in the following article : “A Discrete Look at 1+2+…+n.”

## Step 3: Electronics

I think it is fun to make something physical to illustrate the math. So, I create this LED illustration.

I solder the LEDs on a board and connect the LEDs to Arduino output pins through 1k resistors.

## Step 4: Code

While it is obvious to trace the red dot from the green dots visually, it is more fun and challenging to specify the relationship in code.

Here is the code.

https://gist.github.com/kakittwo/2dbe090583b8192ab...

The key observation is to label the red dots from bottom-up. An illustration of how to index the red dots using the indices of the green dots is shown.

## Discussions