How the black square with symbols works. What does a magic square consist of and how does it work? How to solve a square with an even number of cells

In a magic square, the integers are distributed in such a way that their sum horizontally, vertically and diagonally is equal to the same number, the so-called magic constant.

Magic square in cultures of the world

An example of a magic square is Lo Shu, which is a 3 by 3 table. The numbers from 1 to 9 are written in it in such a way that the sum of each of the lines and the diagonal gives the number 15.

One Chinese legend tells how once during a flood, a king tried to build a canal that would divert water to the sea. Suddenly, a turtle with a strange pattern on its shell appeared from the Lo River. It was a grid with numbers from 1 to 9 inscribed in squares. The sum of the numbers on each side of the square, as well as along the diagonal, was 15. This number corresponded to the number of days in each of the 24 cycles of the Chinese solar year.

The Lo Shu square is also called the magic square of Saturn. On the bottom line of this square there is the number 1 in the middle, and in the upper right cell there is the number 2.

The magic square is also present in other cultures: Persian, Arab, Indian, European. It was captured in his engraving “Melancholy” in 1514 by the German artist Albrecht Durer.

The magic square in Durer's engraving is considered the first to ever appear in European artistic culture.

How to solve a magic square

Solve a magic square by filling the cells with numbers in such a way that the total on each line is a magic constant. A side of a magic square can consist of an even or odd number of cells. The most popular magic squares consist of nine (3x3) or sixteen (4x4) cells. Exists big variety magic squares and their solutions.

How to solve a square with an even number of cells

You will need a piece of paper with a 4x4 square drawn on it, a pencil and an eraser.

Write numbers from 1 to 16 into the cells of the square, starting from the top left cell.

1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16

The magic constant of this square is 34. Swap the numbers on the diagonal line from 1 to 16. For simplicity, swap 16 and 1, and then 6 and 11. As a result, the numbers on the diagonal will be 16, 11, 6, 1.

16 2 3 4
5 11 7 8
9 10 6 12
13 14 15 1

Swap the numbers on the second diagonal line. This line starts with the number 4 and ends with the number 13. Swap them. Now swap the other two numbers - 7 and 10. From top to bottom on the line, the numbers will be located in this order: 13, 10, 7, 4.

16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1

If you count the total on each line, you get 34. This method works with other squares with an even number of cells.

There are several different classifications of magic squares

fifth order, designed to somehow systematize them. In the book

Martin Gardner [GM90, pp. 244-345] describes one of these methods -

by the number in the central square. The method is interesting, but nothing more.

How many sixth-order squares there are is still unknown, but there are approximately 1.77 x 1019. The number is huge, so there is no hope of counting them using exhaustive search, but no one could come up with a formula for calculating magic squares.

How to make a magic square?

There are many ways to construct magic squares. The easiest way to make magic squares odd order. We will use the method proposed by a French scientist of the 17th century A. de la Loubère. It is based on five rules, the action of which we will consider on the simplest magic square of 3 x 3 cells.

Rule 1. Place 1 in the middle column of the first line (Fig. 5.7).

Rice. 5.7. First number

Rule 2. Place the next number, if possible, in the cell adjacent to the current one diagonally to the right and above (Fig. 5.8).

Rice. 5.8. We are trying to put the second number

Rule 3. If new cell extends beyond the square at the top, then write the number in the lowest line and in the next column (Fig. 5.9).

Rice. 5.9. Put the second number

Rule 4. If the cell extends beyond the square on the right, then write the number in the very first column and in the previous line (Fig. 5.10).

Rice. 5.10. We put the third number

Rule 5. If the cell is already occupied, then write the next number under the current cell (Fig. 5.11).

Rice. 5.11. We put the fourth number

Rice. 5.12. We put the fifth and sixth numbers

Follow Rules 3, 4, 5 again until you have completed the entire square (Fig.

Isn’t it true, the rules are very simple and clear, but it’s still quite tedious to arrange even 9 numbers. However, knowing the algorithm for constructing magic squares, we can easily delegate all the routine work to the computer, leaving ourselves only the creative work, that is, writing the program.

Rice. 5.13. Fill the square with the following numbers

Project Magic Squares (Magic)

A set of fields for the program Magic squares quite obvious:

// PROGRAM FOR GENERATION

// ODD MAGIC SQUARE

// BY DE LA LUBERA METHOD

public partial class Form1 : Form

//Max. square dimensions: const int MAX_SIZE = 27; //var

int n=0; // square order int [,] mq; // magic square

int number=0; // current number to write in square

int col=0; // current column int row=0; // current line

De la Lubert's method is suitable for making odd squares of any size, so we can give the user the opportunity to independently choose the order of the square, while wisely limiting the freedom of choice to 27 cells.

After the user presses the coveted btnGen button Generate! , the btnGen_Click method creates an array to store numbers and passes to the generate method:

//CLICK THE "GENERATE" BUTTON

private void btnGen_Click(object sender, EventArgs e)

//order of the square:

n = (int )udNum.Value;

//create an array:

mq = new int ;

//generate a magic square: generate();

lstRes.TopIndex = lstRes.Items.Count-27;

Here we begin to act according to de la Lubert's rules and write the first number - one - in the middle cell of the first row of the square (or array, if you like):

//Generate a magic square void generate())(

//first number: number=1;

//column for the first number is the middle one: col = n / 2 + 1;

//line for the first number - first: row=1;

//put it in a square: mq= number;

Now we sequentially arrange the remaining numbers in the cells - from two to n * n:

//go to the next number:

Just in case, remember the coordinates of the current cell

int tc=col; int tr = row;

and move to the next cell diagonally:

Let's check the implementation of the third rule:

if(row< 1) row= n;

And then the fourth:

if (col > n) ( col=1;

goto rule3;

And fifth:

if (mq != 0) ( col=tc;

row=tr+1; goto rule3;

How do we know that a square cell already contains a number? – It’s very simple: we prudently wrote zeros in all the cells, and the numbers in the finished square are greater than zero. This means that by the value of the array element we will immediately determine whether the cell is empty or already contains a number! Please note that here we will need those cell coordinates that we remembered before searching for the cell for the next number.

Sooner or later we will find a suitable cell for the number and write it into the corresponding cell of the array:

//put it in a square: mq = number;

Try a different way to check the admissibility of a transition to a new one.

wow cell!

If this number was the last, then the program has fulfilled its duties, otherwise it voluntarily moves on to providing the cell with the next number:

//if not all numbers are set, then if (number< n*n)

//go to the next number: goto nextNumber;

And now the square is ready! We calculate its magic sum and print it on the screen:

) //generate()

Printing array elements is very simple, but it is important to take into account the alignment of numbers of different “lengths”, because a square can contain one-, two- and three-digit numbers:

//Print the magic square void writeMQ()

lstRes.ForeColor = Color.Black;

string s = "Magic amount = " + (n*n*n +n)/2; lstRes.Items.Add(s);

lstRes.Items.Add("" );

// print the magic square: for (int i= 1; i<= n; ++i){

s="" ;

for (int j= 1; j<= n; ++j){

if (n*n > 10 && mq< 10) s += " " ; if (n*n >100 && mq< 100) s += " " ; s= s + mq + " " ;

lstRes.Items.Add(s);

lstRes.Items.Add("" ); )//writeMQ()

We launch the program - the squares are obtained quickly and are a feast for the eyes (Fig.

Rice. 5.14. Quite a square!

In the book by S. Goodman, S. Hidetniemi Introduction to algorithm development and analysis

mov, on pages 297-299 we will find the same algorithm, but in an “abbreviated” presentation. It's not as transparent as our version, but it works correctly.

Let's add a button btnGen2 Generate 2! and write the algorithm in the language

C-sharp into the btnGen2_Click method:

//Algorithm ODDMS

private void btnGen2_Click(object sender, EventArgs e)

//order of the square: n = (int )udNum.Value;

//create an array:

mq = new int ;

//generate a magic square: int row = 1;

int col = (n+1)/2;

for (int i = 1; i<= n * n; ++i)

mq = i; if (i % n == 0)

if (row == 1) row = n;

if (col == n) col = 1;

//construction of the square is completed: writeMQ();

lstRes.TopIndex = lstRes.Items.Count - 27;

Click the button and make sure that “our” squares are generated (Fig.

Rice. 5.15. An old algorithm in a new guise

This riddle quickly spread throughout the Internet. Thousands of people began to wonder how the magic square works. Today you will finally find the answer!

The mystery of the magic square

In fact, this riddle is quite simple and made with human inattention in mind. Let's see how the magic black square works using a real example:

  1. Let's guess any number from 10 to 19. Now let's subtract its constituent digits from this number. For example, let’s take 11. Subtract one from 11 and then another one. The result is 9. It doesn't really matter which number from 10 to 19 you take. The result of the calculations will always be 9. The number 9 in the “Magic Square” corresponds to the first number with pictures. If you look closely, you can see that a very large number of numbers are assigned the same pictures.
  2. What happens if you take a number in the range from 20 to 29? Maybe you already guessed it yourself? Right! The result of the calculation will always be 18. The number 18 corresponds to the second position on the diagonal with pictures.
  3. If you take a number from 30 to 39, then, as you can already guess, the number 27 will come out. The number 27 also corresponds to the number on the diagonal of the so inexplicable “Magic Square”.
  4. A similar algorithm remains true for any numbers from 40 to 49, from 50 to 59, and so on.

That is, it turns out that it doesn’t matter what number you guessed - “Magic Square” will guess the result, because in the cells numbered 9, 18, 27, 36, 45, 54, 63, 72 and 81 there is actually the same symbol .

In fact, this mystery can be easily explained using a simple equation:

  1. Imagine any two-digit number. Regardless of the number, it can be represented as x*10+y. Tens act as “x”, and units act as “y”.
  2. Subtract the numbers that make it up from the hidden number. Add the equation: (x*10+y)-(x+y)=9*x.
  3. The number that comes out as a result of the calculations must point to a specific symbol in the table.

It doesn’t matter what number is in the role of “x”, one way or another you will get a symbol whose number will be a multiple of nine. In order to make sure that there is one symbol under different numbers, just look at the table and at the numbers 0,9,18,27,45,54,63,72,81 and subsequent ones.

“Magnet” for wealth, health and so on and so forth...

Pythagoras composed a magic square capable of “attracting” the energy of wealth.

By the way, Henry Ford himself used the Pythagorean square.
He drew it on a dollar bill and always carried it in a secret compartment in his wallet as a talisman.
As is known, Ford did not complain about poverty. At the age of 83, Henry passed on the reins of the corporation and a considerable fortune in the amount of 1 billion dollars (taking into account inflation - more than 36 billion at current prices) to his grandchildren.

*** *** *** *** ***

Numbers inscribed in a square in a special way can not only attract wealth.

For example, the great physician Paracelsus created his own square - the “talisman of health.”

In general, if you construct a magic square correctly, you can let into your life the energy flows that you need.

How to make a personal talismanmagic square of Pythagoras I hope you know how to write numbers and count to ten?

Then go ahead. We draw an energy square that can become your personal talisman.

It has three columns and three rows. There are only nine numbers that make up your individual numerology code.

How to calculate this code?

Let's put it in the first row three digits:

* number of your birthday,
* month of birth
* the year of birth.

For example, you were born on May 25, 1971. Then your first number is the number of the day: 25. This is a complex number, according to the laws of numerology, it must be reduced to a simple one by adding the numbers 2 and 5. It turns out - 7: so we will put the seven in the first cell of the square.

The second is the day of the month: 5, because May is the fifth month. Please note: if a person was born in December, that is, in month number 12, we would have to reduce the number to a simple number: 1 + 2 = 3.

The third is the number of the year. Here everyone will have to reduce it to simple things. So: we decompose 1971 (year of birth) into composite numbers and calculate their sum. 1+9+7+1 = 18, 1+8 =9.

We enter the numbers in the first row: 7, 5, 9.

Let's put the numbers in the second row:

* fourth - your name,
* fifth - middle names,
* sixth - surnames.

We determine them using a table of alphanumeric correspondences.


Guided by it, you add up the digital values ​​of each letter of your name, and, if necessary, reduce the sum to a simple number.

We do the same with patronymic and surname.

For example, Krotov= 3+9+7+2+7+3=31=3+1=4

We now have three numbers for the second line of the energy square

Third row

To fill out the third row, to find the seventh, eighth and ninth numbers, you will have to turn to astrology.

Seventh digit— the number of your Zodiac sign.

Everything is simple here. Aries is the first sign, it corresponds to the number 1. Pisces is the twelfth sign, it corresponds to the number 12.

Attention: in this case, you should not reduce two-digit numbers to simple ones; the numbers 10, 11 and 12 have their own meaning!

Eighth digit— the number of your sign according to the Eastern calendar. It is easy to find it using the table below:

That is, if you were born in 1974, your sign number is 3 (Tiger), and if you were born in 1982, it is 11 (Dog).

Ninth digit- the numerological code of your desire.

For example, you gain energy for the sake of health. So the key word is “health”. We add the letters again according to the first table:

Z - 9, D - 5, O - 7, R - 9, O - 7, B - 3, b - 3, E - 6 = 49, that is, 4 + 9 = 13. Since we have a complex number again, we continue to reduce: 1+3=4

Keep in mind: if you get the numbers 10, 11 and 12, then in this case you should not reduce them.

Well, if you don’t have enough money, then you can calculate the meaning of the words “wealth”, “money” or specifically “dollar”, “euro”.

So, the last ninth digit in your magic square will be a number - the numerological value of your keyword or, in other words, the desire code.

Sing your "square" meditation

Now let’s arrange nine numbers in three rows of three numbers in our magic square.

The drawn square can be framed and hung at home or in the office.

Or you can put it in a folder and put it away from prying eyes. Listen to your inner voice, it will tell you what is right for you.

But that's not all. Learn the numbers of your personal numerological code in the order they appear in the cells.

For what? This is your personal mantra, your direct line to God, if you like. It tunes you to the desired flow from a huge variety of forces in the Universe, and on the other hand, they hear you and respond to your vibrations.

Therefore, you need to learn your mantra by heart. And - meditate.

Repeating your numerological code mentally, sit in a comfortable chair or lie down on the sofa. Relax. Hold your hands palms up, as if receiving energy. After a while, you will feel a tingling sensation in your fingers, vibration, perhaps warmth or, on the contrary, a chill in your palms.

Great: the energy is gone! Meditation lasts until you want to stop, until you feel the need to get up or... until you fall asleep.