Math Proof by LEDs

Introduction: Math Proof by LEDs

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.

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.


int n = 4;
int sum =0 ;
voidsetup() {
for (int i = 0; i < n; i++) {
pinMode(10+ i, OUTPUT);
for (int i = 1 ; i <= n-1 ; i++){
sum += i;
for (int i = 0; i < sum; i++) {
pinMode(i, OUTPUT);
for (int kk =0 ; kk < sum ; kk++){
digitalWrite(kk, LOW);
for (int kk =0 ; kk < n ; kk++){
digitalWrite(10 + kk, LOW);
voidloop() {
for (int i = 0; i < n-1; i++){
for (int j = i + 1 ; j < n; j++){
for (int k = 0 ; k < sum ; k++){
if (k != i + int( 0.5*(j-1-i)*(2*n-j +i) )) {
digitalWrite(k, LOW);
digitalWrite(k, HIGH);
for (int kk = 0 ; kk < n ; kk++){
if (kk != i && kk != j) {
digitalWrite(10+kk, LOW);
digitalWrite(10+kk, HIGH);
view rawled.ino hosted with ❤ by GitHub
Make it Glow Contest 2018

Participated in the
Make it Glow Contest 2018

Be the First to Share


    • CNC and 3D Printing Contest

      CNC and 3D Printing Contest
    • Lamps Challenge

      Lamps Challenge
    • Rice & Grains Challenge

      Rice & Grains Challenge