dacs.doc electric

 

Computers and Creativity,
Computer Programming and mathematics – Magic Squares Continued -Part (2)

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 problem?”. I also believed that the process of programming a model of the thinking process would be a tool to enlighten, clarify, and give me confidence in the solution. I also believed there was a chance that the modeling process would be a good preparation for solving more complex magic squares, which we will attempt in future, articles.

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. 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 an 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?” followed by a bottom up approach to the same question. After all this effort working with M3 we will address M4. The 4x4 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 months article].

Answer: Yes, if we follow the same procedure 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 [[1;2]. 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], 6 in M3 [1;1] , 9 in M3 [1;3] .

c. The resultant matrix is basic M
3 matrix.

8 1 6
3 5 7
4 9 2

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 and 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

Continuing with the M3 magic square, How can we prove we have discovered all 3x3 magic squares? (Remember even though we can look at the magic square from different perspectives such as rotating it or looking at it through a mirror, it is still the same magic square – it just looks different.)

Next month we will discuss a programmed bottom up approach using a computer program design and an analytical top down approach to the solution of this problem.


Charles Bovaird retired from IBM. He is presently Treasurer of DACS. You may contact him at treasurer@dacs.org.

BackHomeNext