dacs.doc electric

 

Computer Programming and Mathematics
Magic Squares Continued - Part 3

by Charles Bovaird Jr.

 

Sometimes we can approach the solution to a problem in more than one way. Two such approaches are (1) top down – and (2) bottom up. Whichever approach you decide to take will be colored with your background, personal preferences, and assumptions on the perceived effectiveness of your choice. In the case of M3, a 3x3 magic square, I chose the top down approach because I was itching to write a program with the potential to answer with conviction the question “Is there a finite number of solutions to the M3 problems, and if so, what are they?” Past successes have strengthened my convictions that the process of programming a model of the thinking process is a tool that can enlighten, clarify, and increase one’s confidence in the solution. We will use a computer model in solving the M3 magic square. It will become the basis for solving the M4 in a future article.

Past experience solving other problems demonstrated value in creating a programming model of the thinking process, since it allowed a study of perspectives not likely found using just paper and pencil. In such a case a computer program model used as a tool for problem solving becomes “A Tool of Thought.” There are many programming languages that have been used in this manner. Depending upon your background and experience some languages are more appropriate than others. Along the way, we will comment on some strengths and weaknesses of some programming languages.

In this article we will answer the questions posed last month, then define a procedural process for generating one solution to M3. Next month we will discuss the design of a top down computer model to address the question “How many solutions are there to the M3 magic square?”

The following problems were posed in last month’s article.

Problem 1: Can you create a 9x9 magic square (with the integer numbers 1 through 81)? [Sorry, the constraint “other than 1,2,…9” was a typo in last month’s article].

Answer: Yes, if we follow the same procedural method that generates an M3 basic magic square as follows:

a. Draw a 3x3 matrix with no values assigned to the 9 cells contained in the “box” we call a matrix. Warning! This process requires you to “think outside the box”.

b. Start with the top (first) row center box M3 [1;2], and place a one (1) in it. Move your pointer up one cell (outside the “box”) and to the right one cell. Since the pointer is now above column 3 (and outside the box) move the pointer to the lowest cell in column 3 M3 [3;3] and place a 2 in it. Now, move the pointer up and to the right one cell. The pointer is now (outside the box) and one cell to the right of row 2. Since we are now outside the box we move our pointer to the opposite end of row 2 and place a 3 in cell 1 of row 2 M3[2;1]. Since this is a 3x3 magic square we have a slight departure from the previous process every 3 moves (the 4th and 7th move). We place the next number (4) in the cell just below where you placed the 3 (place the 4 in M3[3;1] ). Now go back to Start and repeat the process till you finish (5 in M3[2;2], 6 in M3[1;3] , 7 in M3[2;3], 8 in M3[1;1] , 9 in M3[3;2] .

c. The resultant matrix is basic M3 matrix.

8 1 6
3 5 7
4 9 2

Of course, you can get different perspectives of this magic square by flipping it over and/or rotating it.

Using the same procedure an M5 will look like this:

M5 =
17 24 1 8 15
23 5 7 14 12
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9

Problem 2: The maximum number of Modd magic squares that can be generated is infinite since there is no limit to how large an odd number can be.

Problem 3: Other magic squares can be generated from any basic magic square if we are not limited to an integer sequence beginning with 1. For example, if we take the basic 3x3 magic square and add 1/3 to all cells we get a magic square that adds to 16.

81/3 11/3 61/3
31/3 51/3 71/3
41/3 91/3 21/3

Next month, we will continue with the M3 magic square and answer the question “How can we prove we have discovered all 3x3 magic squares?” Our solution will use a computational model as a “tool of thought.”


Charlie Bovird is DACS Treaasurer

Copyright © 2004 Charles F. Bovaird Jr.

BackHomeNext