Saturday, October 15, 2016

Magic triangle

What is this magic triangle.. what could it be . Let me break the suspense, this is a number puzzle. Like every triangle, this one also has three sides. Each of its sides contains equal amount of some numbers. ( numbers that do not repeat itself. In our case, we want it to be from a set of consecutive numbers )  And the sum of the numbers placed on each side turn out to be the same.

That is, like this : Arrange numbers from 1-9 on a magic triangle of size 4, such that each side adds up to the same number. Now, this is not that difficult. If not anything, we could always try a trial and error after ruling out some obviously impossible combinations. ( like the big numbers 8,9 don't end up on the same side) 
Take a break and try arranging the numbers so that they add up to 17 on each side. Try it!! 

That's great.. now, what if I asked you to arrange numbers from 1-15 in a magic triangle of side length 6. Now what would you do? Would be real crazy and time consuming to try out combinations for those many numbers. What to do...  what do we usually do... the first approach to trying to come up with an algorithm that will help us work out triangles of any length, would be , to start off with smallest case. Triangle of size 3, then try triangle of size 4. Then see if we could generalise it. Again, take sometime if you feel like giving it a try. I can wait. 

This is the algorithm I found useful and pray that it works for laarge numbers too..  Time to visualise our triangle. Imagine a triangle with three vertices named as A, B and C. ( The side BC is the horizontal side , the AB is the left side and AC is the right side )

You are given a series of consecutive numbers to fit into the triangle along its sides equally so that the sum of each individual side is the same . 

Start with the vertex A. That is, the first number of the series, place it on A. The next number on B and the third number on C. Now, remember this rule : every number thereafter follows a pattern, wherein , each side gets a turn, that is, each side gets a number and waits two turns to get the next number. ( that is no two consecutive numbers go to the same side . You will understand this better with an example. ) 

While distributing the numbers now, say n, n+1, and n+2 ( three consecutive numbers ) , we already said, each side gets one. But which side should get which number is the thing to concentrate on. Out of the three numbers, the middle number always goes to the side BC( the horizontal side ) . The first number goes to the right side in the first iteration, and in the second iteration the first number goes to the left side (alternatively that is).

To apply all this confusing data on an example : Vertex A gets 1, B gets 2 and C gets 3. Number 4 goes to the right side, 5 to the horizontal side, 6 to the left side. Now iteration 2, number 7 goes to left side first, 8 ( middle number ) goes to horizontal side and 9 goes to the right side now. You see , 1,2,3 sat on the vertices. 4,5,6 -  start from  right side, middle in horizontal side, 6 on the left side. next iteration : 7,8,9 ( this time, we start from left side ) left gets 7, horizontal gets 8 and right gets 9. 

We do this till we reach the last iteration. The last three numbers : till now we were trying to balance the sides so that they all had more or less similar sum, last turn we make the sum equal. The last iteration, say x, x+1, x+2. Again, each side gets one number each.  For the last iteration, the first number x goes to the horizontal base. But where x+1 goes depends on which side's turn it is. ( if in the previous iteration, the left side got the first number in the series, this turn the right side gets the second number. In simpler terms, if it's an odd iteration, pick the right side, and for an even iteration pick the left side. ) Ta daa.. there comes our magic triangle.

Quick recap : First three numbers on vertices in anti clockwise order. The next three number follow a pattern: middle number always on BC. Where the first number goes depends on the iteration number. First iteration, first number goes to the right side, second iteration, it goes to the left side.. you do this till you are left with the last three numbers. The last turn, you add the first number to BC, and depending on which side's turn it is, you send the next number there. And the last number to whichever side is left. Voila!!

Example, we build a 5 sided equal-sum-sided-triangle. 
Step 1: add 1,2,3 to vertices A,B and C respectively
Step 2 : next numbers to fill : 4,5,6 . First iteration, we start with right side. AC gets 4. Middle number always to the horizontal side. So 5 goes to BC. And 6 to the left over side , side AB. 
Step 3: next numbers to fill : 7,8,9. Second iteration , so we start with the left side. AB gets 7. As usual BC gets 8 and AC gets 9. 
Step 4: we have reached the last three numbers ( each side already has 4 numbers each ) numbers to fill in : 10,11,12. Because it is the last step, the least number goes to BC. Add 10 to BC. This is iteration 3. Odd iteration, meaning right side's turn. So next number 11 goes to side AC. And 12 goes to AB. Done.. How simple was that now!

Remember the fun part is, you can extend this magic triangle to any size and you do not have to break your head over a gazillion trial and error combinations.  Phew!! How cool is that now!! You know magic too now. Mathematical magic.. hocus pocus dabba dooo... let the magic triangle appear through!

No comments:

Post a Comment