of 13
8/12/2019 SPECIAL MAGIC SQUARES OF ORDER SIX AND EIGHT
1/13
Special Magic Squares of Order Six and Eight
S. Al-Ashhab
Assistant Professor
Department of Mathematics, Al-albayt University,
Visiting ProfessorUm Alqura university (KSA)
Email: [email protected]
Abstract:
In this paper we introduce and study special
types of magic squares of order six. We list
some enumerations of these squares. We
present a parallelizable code. This code is
based on the principles of genetic algorithms.
KeywordsMagic Squares, Four Corner Property, Parallel
Computing, Search Algorithms, Nested loops.
1 Introduction
A magic square is a square matrix, where
the sum of all entries in each row or column
and both main diagonals yields the samenumber. This number is called the magic
constant. A natural magic square of order n is
a matrix of size nn such that its entries
consists of all integers from one to n. The
magic constant in this case is2
1)n(n + . A
symmetric magic square is a natural magic
square of order n such that the sum of all
opposite entries equals n+1. For example,
Table 1a natural symmetric magic square
15 14 1 18 17
19 16 3 21 6
2 22 13 4 24
20 5 23 10 7
9 8 25 12 11
A pandiagonal magic square is a magicsquare such that the sum of all entries in all
broken diagonals equals the magic constant.
For example, we note in table 2 that the sum ofthe entries 39,12,46,22,20,23,13 is 175, whichis the magic sum. These entries represent the
first right broken diagonal.
Table 2 a natural pandiagonal and symmetric magic
square of order seven
1 39 34 21 35 8 37
27 9 12 36 24 19 48
40 30 17 46 7 32 3
45 6 28 25 22 44 5
47 18 43 4 33 20 10
2 31 26 14 38 41 23
13 42 15 29 16 11 49
In the seventeenth century Frenicle de
Bessy claimed that the number of the 4x4magic squares is 880, where he considered a
magic square with all its reflections and
rotations one square. Hire listed them all in atable in the year 1693. Recently we can use thecomputer to check that there are
880*8 = 7040
magic squares of order 4.
In 1973 the number of all natural magic
squares of order five became known.
Schoeppel computed it using a PDF-10
machine. It is64 826 306*32=2 202 441 792
where we multiply with 32 due the existenceof type preserving transformations. According
to [5] there exists
736 347 893 760
natural nested magic squares of order six.
It is well-known that there are pandiagonalmagic squares and symmetric squares of order
five. But, there are neither pandiagonal magic
squares nor symmetric squares of order six.
International Journal of Digital Information and Wireless Communications (IJDIWC) 1(4): 733-745The Society of Digital Information and Wireless Communications, 2011(ISSN 2225-658X)
733
8/12/2019 SPECIAL MAGIC SQUARES OF ORDER SIX AND EIGHT
2/13
The number of natural magic squares of order
six is actually till now unknown. Trump madeusing statistical methods (Monte Carlo
Backtracking) the following intervalestimation for this number
(1.7712e19, 1.7796e19)
with a probability of 99%.We give here the number of a subset of
such squares. We define here classes of magic
squares of order six, which satisfy some of the
conditions for both types.
The most-perfect pandiagonal magic
squares of McClintock (cf. [11]) for which
Ollerenshaw and Bres (cf. [10])
combinatorial count ranks as a majorachievement, draw attention to another typewhich have the same sum for all 2 by 2
subsquares (or quartets). The number of
complete magic squares of order four is 48,
and the number of complete magic squares of
order eight (cf. [10]) is
368 640.
Ollerenshaw and Bre (cf. [10]) have a patent
for using most-perfect magic squares forcryptography, and Besslich (cf. [7] and [8])
has proposed using pandiagonal magic squaresas dither matrices for image processing.
A pandiagonal and symmetric magic square
is called ultramagic. According to [14] thenumber of ultramagic squares of order five is
16 and number of ultramagic squares of orderseven is
20 190 684.
The weakest property of a square is being
semi magic. By this concept we mean a
matrix, where the sum of all entries in eachrow or column yields the magic constant.
According to Trump (cf. [14]) the number of
semi magic squares of order four is68 688,
and the number of semi magic squares of order
five is
579 043 051 200.
Bi-magic squares are magic squares that when
the entries are squared, it also forms a magicsquare. Here is a bi-magic square of order six
Table 3a bi-magic square
17 36 55 124 62 114
58 40 129 50 111 20
108 135 34 44 38 49
87 98 92 102 1 28
116 25 86 7 96 78
22 74 12 81 100 119
We focus in this paper on the following
kind of magic squares: magic squares of order
6 )(a ij with magic constant 3s such that
ija +
3)3)(j(ia
+++
3)i(ja
++
3)j(ia
+= 2s
holds for each i=1,2,3 and j=1,2,3 and
33a +
44a +
34a +
43a = 2s.
We call such squares four corner magic square
of order 6. The entries of a four corner magic
square of order 6 satisfy
14a +
25a +
36a +
41a +
52a +
63a =3s,
13a +
22a +
31a +
46a +
55a +
64a = 3s
These two conditions represent the sum of theentries of two broken diagonals. If the magic
square is pandiagonal, then we have to
consider all broken diagonals. To see the
validity of the first equation we know from the
definition that
11a +
44a +
14a +
41a = 2s,
22a +
55a +
25a +
52a =2s,
33a +
66a +
36a +
63a =2s
holds. Adding up these equations andsubtracting from them the following equation
11a +
22a +
33a +
44a +
55a +
66a = 3s
yields the desired equation.
We introduce now the main concept in our
work. We call a four corner magic squares
)(aij
such that
33a +
44a = s and
34a +
43a = s.
International Journal of Digital Information and Wireless Communications (IJDIWC) 1(4): 733-745The Society of Digital Information and Wireless Communications, 2011(ISSN 2225-658X)
734
8/12/2019 SPECIAL MAGIC SQUARES OF ORDER SIX AND EIGHT
3/13
a four corner magic square of order 6 with
symmetric center. This means that the 2 by 2square in the center is symmetric. A four
corner magic squares with symmetric center isa four corner magic square of order 6 can be
written as
Table 4 a symbolic four corner magic squares with
symmetric center
x f g t G M
z h n j q N
w E e a m D
A k sa se H R
2sj
oz
p D o 2sp
qh
T
B F W J L p+qx
whereA=e+s t x,
B = j+o+t e w,
D=d+g+n+x a p q,
E=3s a e m w D,
F=3s f h k p E,
G = j+o+p+q+s e f g w x,
H=e+g+s+w+x j k o p q,
J=2s+e j o a t,M=3s f g t x G,
N=3s h j n q z,
L=f+h+k+p m s,R=s+a+e k A H,
T=h+j+q+z d s,
W=a+2s d e g n.
Table 5 a natural four corner magic squares with
symmetric center
6 23 11 13 33 25
19 28 36 3 7 182 29 1 17 27 35
21 8 22 34 10 16
32 9 15 20 30 5
31 14 26 24 4 12
We see that it has seventeen independent
variables. We can consider a special class of
the class of four corner magic squares with
symmetric center. The squares, which can bewritten in the following form, will be called
four corner magic squares with double
symmetric center.
Table 6 a symbolic four corner magic squares withdouble symmetric center
x f g t I s+w+ej
ot
Z h s o j q o+2sj
hqz
w sR e a m g+s+xajo
A sm s a se R a+j+o+t
egw
2sj
oz
sq sj o sh h+2j+q+
z 2sB K a+j+o
eg
J Q sx
where
A=e+s t x,
B = j+o+t e w,I = j+o+2s e f g w x,
J = 2s+e j o a t,
K = e+g+2m+q+w+x f h j o s,
Q = f+h+s 2m q,
R = e+g +m+w+x j o s,
2 Four corner magic squareThis concept was first introduced in [1].
Alashhab considered there the type called
nested four corner magic square with a
pandiagonal magic square. By this kind of
squares we mean matrices having the
following structure
YpdcZb37fA14A13A12A11f37XA24A23A22A21X37WA34A33A32A31W37VA44A43A42A41V37b37p37d37c37Z37Y
where
International Journal of Digital Information and Wireless Communications (IJDIWC) 1(4): 733-745The Society of Digital Information and Wireless Communications, 2011(ISSN 2225-658X)
735
8/12/2019 SPECIAL MAGIC SQUARES OF ORDER SIX AND EIGHT
4/13
V=37 +afj,
W=37+gbd,X=111 a b c g h,
Y=111 b c d h j,Z= h+j p,
and the inside square (matrix A) is
74ghjjhgh+jaa+gj74agha37h37gg+h+j3737j
a+g+h2s37a37+ahj37+jag
We note that the inside 4x4 square is apandiagonal square. The number of the naturalmagic squares of this kind is
32*79118 = 2531776
Here the number 32 refers to the 32 type
preserving transformations, which are any
mixture of the following transformations:
1) Rotation with angle2 counter
clockwise,
2) Transpose of the matrix,3) Exchange the second and fifth entry of
the first and last row,
4) Exchange the second and fifth entry ofthe first and last column.
2.1. Property preserving transformations
There are seven classical transformations,which take a magic square into another magic
square. They are the combinations of the
rotations with angles /2, , (3)/2 and
transpose operation. Now, a four corner magic
squares with symmetric center can be
transformed as follows into another one of the
same kind: we make these interchanges
simultaneously: interchange12
a (res.62
a )
with15
a (res.65
a ), interchange21
a (res.26
a )
with51
a (res.56
a ), interchange22
a (res.55
a )
with25
a (res.52
a ), interchange23
a (res.
24a ) with
53a (res.
54a ), interchange
32a (res.
42a ) with
35a (res.
45a ).
We can use this transformation to reducethe number of computed natural magicsquares. In order to eliminate the effect of the
previous transformations we compute all
natural four corner magic squares with
symmetric center for which the following
conditions hold:
p
8/12/2019 SPECIAL MAGIC SQUARES OF ORDER SIX AND EIGHT
5/13
We consider the problem of counting the
natural four corner magic squares with doublesymmetric center. Regarding these squares we
eliminate the effect of the seven classicaltransformations by requiring
q< h , 1 q 17, h 18 ..... (2.1)
When we hold the entries q and h, then we
can transform the square into another square
of the same kind. This is possible by
interchanging the first row (res. column) withthe last row (res. row) and simultaneously
interchanging the two middle rows (res.
columns). Hence, the number of naturalsquares by fixed values of q and h is divisible
by four. Actually, there is a third propertypreserving transformation. If we take the dual
of the square, and reflect about the main right
diagonal followed by a reflection about the
main left diagonal, then we obtain a naturalfour corner magic squares with double
symmetric satisfying (2.1). For example, the
following square is a natural four corner magic
squares with double symmetric satisfying the
condition (2.1):
15 24 9 16 33 14
32 7 27 19 1 25
20 26 2 3 31 29
8 6 34 35 11 17
13 36 18 10 30 4
23 12 21 28 5 22
This square will be transformed according to
the last transformation into the followingsquare
15 32 9 16 25 14
33 7 27 19 1 24
20 26 2 3 31 29
8 6 34 35 11 17
12 36 18 10 30 5
23 4 21 28 13 22
Hence, the number of natural four corner
magic squares with double symmetric centerby fixed values of q and h is divisible by eight.
2.2. Number of squares
We used computers to count several types
of magic squares. The algorithm is constructed
in such a way that we take specific values at
the beginning. In the case of four corner magic
squares we fix by each run of the code two
specific values for a and e, which satisfy the
following conditions
a < e,1 a 17,
e 18.
The algorithm uses then nested for-loops
representing the independent variables (the
small letters) in order to assign all possible
values for these variables between 1 and 36.
When we make a specific assignment for the
independent variables, we substitute in the
formulas, which are written in the definition.
This determines a numerical matrix, which isthen examined to be a possible magic square
or not, i. e. the computed value for being in the
range from 1 to 36 and for being differentfrom other existing values.
We used Pentium IV computers core 2 duo
CPU (3 GHz) to count the four-corner magicsquares with semi-symmetric center. It took
about two months to finish. The C code is
presented in the appendix. The code is
parallelizable since we can fix the value of the
outer for-loop before running the code. By thisway we can split the task into 36 tasks, which
can run in parallel.
We list the number for all squares withrespect to different values of a and e in the
following tables:
International Journal of Digital Information and Wireless Communications (IJDIWC) 1(4): 733-745The Society of Digital Information and Wireless Communications, 2011(ISSN 2225-658X)
737
8/12/2019 SPECIAL MAGIC SQUARES OF ORDER SIX AND EIGHT
6/13
Table 7 a list of the number of four corner magic
squares with a=1,2
a e number a e number
1 2 80012582 2 3 1387041061 3 93587366 2 4 138566816
1 4 137572494 2 5 166212466
1 5 130446558 2 6 156797758
1 6 161682674 2 7 172088726
1 7 194448126 2 8 186805792
1 8 175127312 2 9 188437984
1 9 177194810 2 10 187515974
1 10 193502584 2 11 203101826
1 11 185469236 2 12 192563748
1 12 196104980 2 13 198537572
1 13 194270982 2 14 200999970
1 14 195467492 2 15 194713394
1 15 187447864 2 16 191759218
1 16 195084338 2 17 203881432
1 17 184936940 2 18 185508218
1 18 190538808
Table 8a list of the number of four corner magic
squares with a=3, 4
a e number a e number
3 4 166984902 4 5 176458428
3 5 157057934 4 6 177214506
3 6 178288550 4 7 192022722
3 7 174733174 4 8 187140692
3 8 185501038 4 9 196003756
3 9 190481524 4 10 203009482
3 10 197666168 4 11 197765138
3 11 189738168 4 12 200327396
Table 9 a list of the number of four corner magic
squares with a=3, 4
a e number a e number3 12 207005744 4 13 207983258
3 13 198104476 4 14 197878610
3 14 197186976 4 15 201703132
3 15 194821376 4 16 195874772
3 16 195261598 4 17 184054844
3 17 193169344 4 18 187361040
3 18 182197140
Table 10 a list of the number of four corner magic
squares with a=5,6
a e number a e number
5 6 182674758 6 7 1920227225 7 185076984 6 8 190067620
5 8 202246296 6 9 200239806
5 9 186078138 6 10 192906394
5 10 199812094 6 11 197264336
5 11 211074178 6 12 204338134
5 12 204847206 6 13 203936564
5 13 201808012 6 14 202150964
5 14 228209842 6 15 204245156
5 15 197562226 6 16 188724932
5 16 195399258 6 17 185672352
5 17 195513800 6 18 185229452
5 18 186946600
Table 11 a list of the number of four corner magic
squares with a=7,8
a e number a e number
7 8 198867408 8 9 201833290
7 9 198535068 8 10 200137238
7 10 202469588 8 11 218984602
7 11 192498024 8 12 194348924
7 12 205310982 8 13 196333868
7 13 198048566 8 14 202921386
7 14 201259028 8 15 192255112
7 15 201184468 8 16 190172216
7 16 192323906 8 17 208098890
7 17 189866824 8 18 189151120
7 18 192803750
Table 12 a list of the number of four corner magic
squares with a=9, 10
a e number a e number9 10 210139916 10 11 205746730
9 11 197103700 10 12 202161512
9 12 208482002 10 13 205937482
9 13 198459704 10 14 190702480
9 14 196245850 10 15 186280692
9 15 187397670 10 16 186260912
9 16 186039290 10 17 186234712
9 17 188258346 10 18 185507292
9 18 193867030
International Journal of Digital Information and Wireless Communications (IJDIWC) 1(4): 733-745The Society of Digital Information and Wireless Communications, 2011(ISSN 2225-658X)
738
8/12/2019 SPECIAL MAGIC SQUARES OF ORDER SIX AND EIGHT
7/13
Table 13 a list of the number of four corner magic
squares with a=11,12
a e number a e number
11 12 201527484 12 13 19861796211 13 195908880 12 14 190414138
11 14 197655756 12 15 190263702
11 15 185552014 12 16 192317526
11 16 201069568 12 17 187546684
11 17 186852956 12 18 188181614
11 18 180859498
Table 14 a list of the number of four corner magic
squares with a=13,14
a e number a e number
13 14 198697560 14 15 18846315213 15 194493502 14 16 197238686
13 16 191413396 14 17 229808362
13 17 190031104 14 18 195395024
13 18 197288494
Table 15 a list of the number of four corner magic
squares with a=15, 16, 17
a e number a e number
15 16 205305156 16 17 193594738
15 17 199979596 16 18 202198792
15 18 199645518 17 18 226528028
The total number of the squares is
28 634 584 244.Hence, there are
28 634 584 244*2*8=458 153 347 904
different natural squares. The number of pairs
(a,e) is 153. Each pair determines uniquely a
center of the square. The average of squares
per center is
2.995e9153
044581533479=
There are 3429 possible centers of the natural
four corner magic squares. Based on the
information about the considered 153 centers
of the natural four corner magic squares we
estimate their total number to be
13e103429*2.995e9 13 =
Also, we present the count of the natural
four corner magic squares with doublesymmetric center. We list the number with
respect to all values of q in the following
table:
Table 16 a list of the number of natural four corner
magic squares with double symmetric center
q number q number
1 976800 10 391968
2 996096 11 376064
3 894816 12 263216
4 808608 13 230736
5 7977472 14 217616
6 640592 15 1399687 595024 16 85200
8 515344 17 78096
9 458784
The total number of the squares is 15646400.
Hence, there are15 646 400*8=125 171 200
different natural squares.
3 Semi pandiagonal magic squares
We introduce a generalization of the
concept of four corner magic square. This
square will be called semi pandiagonal magic
square. It is a magic square with the threeadditional conditions: the middle right and left
broken diagonal sum up to the magic constant.
The sum of the elements in the center 2x2
square is two-third the magic constant. Theformula for such squares is
Table 17a symbolic semi pandiagonal magic squarea D c d f G
H 2semo k l m H
A r u v J K
Q p z 2suvz y L
N o i x e M
B E Q R F N
where
International Journal of Digital Information and Wireless Communications (IJDIWC) 1(4): 733-745The Society of Digital Information and Wireless Communications, 2011(ISSN 2225-658X)
739
8/12/2019 SPECIAL MAGIC SQUARES OF ORDER SIX AND EIGHT
8/13
A=d +l+m+o+p+q+x+ycs2uvz,
B=c+4s+2u+v+zxyadhlmnop2q,D=4s+2u+2v +2z2a2dfhlnp2qxy,
E=2a+2d+e+f+h+l+m+n+2q+x+yr3s2u2v2z,
F=k+l+p+r+i+xefms,
G=a+d+h+l+n+p+2q+x+ycs2u2v2z,
H=e+o+sklh,
J=4siklprxy,
K=c+k+i+u+zdmoq,
L=s+u+vqpy,
M=3seinox,N=m+o+v+zas,
Q=3scikuz,
R=s+u+zdlx.
We note here that this square is a magicsquare with the magic constant is 3s. Further,
the sum of both entries d, m ,K, q, o, Q and c,
2some, A, L, e, R is equal to 3s. We can
easily check that any four corner magic squarewith symmetric center satisfy the conditions
imposed on the semi pandiagonal magic
square.
We have now twenty independentvariables. We note that the inside 4 by 4
square is given in the following table:
2some k l m
r u v J
p z 2suvz y
o i x e
The variable J can be determined by variables,which do not appear in the outer frame.
Further, the elements of the outer frame of thissquare do not depend on the variables of the
center.
The semi pandiagonal magic square will
be transformed into another one of the same
type by applying the eight classicaltransformations. It has another property
preserving transformation. In fact, the square
in table 17 can be transformed into the
following one
a f c d D G
N e i x o M
A J u v r K
Q y z 2s-u-v-z p L
H m k l 2s-o-m-e H
B F Q R E N
without losing its magic properties.
4 Franklin squares
We are here interested in Franklin squares of
order eight, which are semi magic squares (cf.
[2], [3] and [4]). They have some similarities
to four corner magic squares. As explained by
Franklin, each row and column of the square
have the common sum 260. Also, he notedthat half of each row or column sums to half of260. In addition, each of the ''bent rows'' (as
Franklin called them) have the sum 260. The
total number of natural Franklin squares is
1 105 920.
The general form of a Franklin square with
magic constant 2s is an eight by eight matrix
consisting of 16 blocks arranged as follows:
B1 B2 B3 B4
B5 B6 B7 B8
B9 B10 B11 B12
B13 B14 B15 B16
The blocks are defined in the following way:
Table 18Block B1
-j+f+2b-q+x-p s+j-f-2b-x
j-2b-x+m+q+p -j+2b+x-m
Table 19Block B2
-s+f+k+q+x+p s-k-x-f
s+m-k-q-x-p -m+k+x
International Journal of Digital Information and Wireless Communications (IJDIWC) 1(4): 733-745The Society of Digital Information and Wireless Communications, 2011(ISSN 2225-658X)
740
8/12/2019 SPECIAL MAGIC SQUARES OF ORDER SIX AND EIGHT
9/13
Table 20Block B3
b-q+x s-b-p-x
p+q-b b
Table 21Block B4
j +k+2p+q+xb s b+sjkpx
b+skjpq j+kb
Table 22Block B5
-f+b-k-q-p+s f-b+k
-m-b+k+q+p m+b-k
Table 23Block B6
j-f-b+q+p f+b-j
s-j-m+b-q-p j+m-b
Table 24Block B7
-j+2b-k-2p-q+s j-2b+k+p
j-2b+k-x+q+p -j+2b-k+x
Table 25Block B8
q p
s-q-p-x x
Table 26 Block B9
a+b+x+fj sbxfa+mbx+j m+b+x
Table 27Block B10
a+b+f+k+xs s+jbf kx
baxk+m+s b+k+xjm
Table 28Block B11
p+xa sjxp
A j
Table 29 Block B12
p+a+x+j+ks skpxsajk k
Table 30 Block B13
sa fk fj+k
km+a jk+m
Table 31Block B14
j+af f
sajm m
Table 32Block B15
b+s a j k p pb+k
j+axb+k x+bk
Table 33Block B16
a+bp j+pb
sabx b+xj
We notice that the sum of all entries in each
block is s.
Using Maple we computed the
characteristic polynomial of this 8 by 8 matrix.
It is5678 )(4 EDxb +++
where
222 2kj+2b+qxpxkx2jx
km+jm+kq2kpjq+2bx+axjk2bs
bqbp2ap2bk+3bjakajab=F
F]+f2q)2pkj2b(
q)s2p2kjfa(2b8[+4s=D 2
222 2kj+2b+qxpxkx2jxkm+jm
+kq2kpjq+2bx+axjk2bmbqbp2ap2bk+3bjakajab=L
L]s+f2q)2pkj2b16[(+s=E 2
We see that the eigenvalue zero has
algebraic multiplicity five. Hence, the rank of
the Franklin square is at most three in general.
The investigation of the natural Franklinsquares shows that the rank is always three.
5 Applications of magic squares
The main area of the application of magic
squares to music is in rhythm, rather than
notes. This is because for rhythm, consecutive
numbers 1 to 2n are not used to fill the cells of
the nn magic square. This relationship is:
International Journal of Digital Information and Wireless Communications (IJDIWC) 1(4): 733-745The Society of Digital Information and Wireless Communications, 2011(ISSN 2225-658X)
741
8/12/2019 SPECIAL MAGIC SQUARES OF ORDER SIX AND EIGHT
10/13
The total sum of the magic squares numbers
is equal to central number x 9
This is important to music as it shows the sizeof the magic square, which is how many
pulses or sub-divisions there are in the
sequence, this will indicate how and where to
apply it.Table 34 Magic square for rhythm
3 5 7
5 8 11
7 11 15
Using table 34 as an example, 8x9=72 gives
the size of the magic square. This can
therefore be applied to a piece of music with
18 crotchet beats since 18x4=72. Rests can
also be added between the first and second or
second and third rows to create a feeling of the
music building towards a cadence. By
choosing different values for the rests, the
same magic square can create many differentmusical passages. Finally, we mention that
semi magic squares have applications todigital halftoning.
6 Conclusions
We have introduced several types of magic
squares. The problem of counting these
squares is not completely solved yet. We can
find some numbers and estimations in [14].
The development of computers can help bythis task. In this paper we presented some
counting and ideas how to count. In the futurethis research can be extended to include more
types and give counting for the introduced
types. The code, which we presented, is based
on the idea of search over all possibilities insuch a way that we continue the search at each
dead end from the nearest exit.
7 PROGRAM CODE (The C-code)#include
#include
#include
#include
#include
#include #include
const int N = 6; const int NN =
N*N;const int Sum2 = NN - 1;
const int Sum4 = Sum2 + Sum2; const
int Msum = Sum2 + Sum4;
struct bools {bool used[NN];};
struct bools allFree;
#define Uint unsigned int
void writeSquare(int *p, FILE *wfp)
{char squareString[120], *s =
squareString; int cells = 0;
{int i; for (i = 0; i < NN; ++i)
{int x = p[i] + 1;
if (x < 10) { *s++ = ' '; *s++ = '0'+ x; }
else if (x < 20) { *s++ = '1';
*s++ = '0' - 10 + x; }
else if (x < 30) { *s++ = '2';
*s++ = '0' - 20 + x; }
else { *s++ = '3'; *s++ = '0' -
30 + x; }
if (++cells == N) { *s++ = '\n';
cells = 0; } else *s++ = ' ';}}
*s++ = '\n'; *s++ =
'\0';fputs(squareString, wfp);}
Uint makeSquares(int a, int b, int e,
int J, FILE *wfp){Uint count = 0, pcount = 0; bools v
= allFree; int Z[NN];
Z[20]=J;v.used[e] = true; v.used[a] =
true; v.used[b] =
true;v.used[J] = true;
{int t; for (t = 1; t < 2 ; ++t) if
(!v.used[t]) {v.used[t] = true;
{int x; for (x = 21; x < 22; ++x) if
(!v.used[x]) {Z[18] = Sum4-b-t-x;
if ((Z[18] < 0) || (Z[18] >= NN) ||
v.used[Z[18]] || (Z[18] == x))
continue;
v.used[x] = true; v.used[Z[18]] =
true;{int j; for (j = 0; j < NN; ++j)if (!v.used[j]){v.used[j] = true;
{int o; for (o = 0; o < NN; ++o) if
(!v.used[o]) { Z[33]=Msum-j-b-o-a-t;
if ((Z[33] < 0) || (Z[33] >= NN) ||
v.used[Z[33]] || (Z[33] == o))
continue;v.used[o] = true;
v.used[Z[33]] = true;
{int z; for (z = 0; z < NN; ++z) if
(!v.used[z]) {Z[24]= Sum4-j-z-o;
if ((Z[24] < 0) || (Z[24] >= NN) ||
v.used[Z[24]] || (Z[24] == z))
continue; v.used[z] = true;
International Journal of Digital Information and Wireless Communications (IJDIWC) 1(4): 733-745The Society of Digital Information and Wireless Communications, 2011(ISSN 2225-658X)
742
8/12/2019 SPECIAL MAGIC SQUARES OF ORDER SIX AND EIGHT
11/13
v.used[Z[24]] = true;
{int w; for (w = 0; w < NN; ++w)
if (!v.used[w]){Z[30]=b+j+o+t-w-Sum2;
if ((Z[30] < 0) || (Z[30] >= NN) ||v.used[Z[30]] || (Z[30] == w))
continue;
v.used[w] = true; v.used[Z[30]] =
true;
{int p; for (p = 0; p < (NN-1); ++p)
if (!v.used[p]) {v.used[p] = true;
{int q; for (q = p+1; q < NN; ++q) if
(!v.used[q])
{Z[5]=Sum4-o-p-q-j-t+w+e;
if ((Z[5] < 0) || (Z[5] >= NN) ||
v.used[Z[5]] || (Z[5] == q))
continue;
Z[35]=Sum2-b+p+q-x-e;
if ((Z[35] < 0) || (Z[35] >= NN) ||v.used[Z[35]] ||(Z[35] == q) ||
(Z[35] == Z[5])) continue;
v.used[q] = true; v.used[Z[5]] =
true; v.used[Z[35]] = true;
{int h; for (h = 2; h < 3; ++h) if
(!v.used[h]) {Z[28]= Sum4-p-q-h;
if ((Z[28] < 0) || (Z[28] >= NN) ||
v.used[Z[28]] || (Z[28] == h))
continue;
v.used[h] = true; v.used[Z[28]] =
true;
{int n; for (n = 0; n < NN; ++n) if
(!v.used[n]) {Z[11]= Msum-j-z-n-q-h;if ((Z[11] < 0) || (Z[11] >= NN) ||
v.used[Z[11]] || (Z[11] == n))
continue; v.used[n] = true;
v.used[Z[11]] = true;
{int d; for (d = 0; d < NN; ++d) if
(!v.used[d]) {
Z[29]=Msum-Z[24]-p-d-o-Z[28];
if ((Z[29] < 0) || (Z[29] >= NN) ||
v.used[Z[29]] || (Z[29] == d))
continue; v.used[d] = true;
v.used[Z[29]] = true;
{int g; for (g = 0; g < NN; ++g) if
(!v.used[g]) {Z[32]= a+b-d-g-n+Sum2;
if ((Z[32] < 0) || (Z[32] >= NN) ||v.used[Z[32]] || (Z[32] == g))
continue; Z[17]=d-a+g+n-p-q+x;
if ((Z[17] < 0) || (Z[17] >= NN) ||
v.used[Z[17]] || (Z[17] == g) ||
(Z[17] == Z[32])) continue;
Z[23]=a+b-g+j+o+p+q+t-w-Sum4;
if ((Z[23] < 0) || (Z[23] >= NN) ||
v.used[Z[23]] ||(Z[23] == g) ||
(Z[23] == Z[32]) || (Z[23] == Z[17]))
continue;
v.used[g] = true; v.used[Z[32]] =
true; v.used[Z[17]] = true;
v.used[Z[23]] = true;
{int f; for (f = 34; f < 35; ++f) if
(!v.used[f]) {Z[4]=Msum-x-g-t-f-Z[5];
if ((Z[4] < 0) || (Z[4] >= NN) ||v.used[Z[4]] ||(Z[4] == f))
continue; v.used[f] = true;
v.used[Z[4]] = true;
{int m; for (m = 0; m = NN) ||
v.used[Z[13]] || (Z[13] == m))
continue; v.used[m] = true;
v.used[Z[13]] = true;
{int k; for (k = 0; k < NN; ++k) if
(!v.used[k]) {
v.used[k] = true; Z[22]=Msum-k-b-
Z[18]-Z[23]-Z[20];if ((Z[22] >= 0) && (Z[22] < NN) &&
!v.used[Z[22]]) {
v.used[Z[22]] = true;
Z[34]=Msum-m-q-Z[4]-Z[22]-Z[28];
if ((Z[34] >= 0) && (Z[34] < NN) &&
!v.used[Z[34]]){v.used[Z[34]] = true;
Z[31]=Msum-f-h-k-p-Z[13];
if ((Z[31] >= 0) && (Z[31] < NN) &&
!v.used[Z[31]]) {
Z[0]=x; Z[1]=f; Z[2]=g; Z[3]=t;
Z[6]=z; Z[7]=h; Z[8]=n; Z[9]=j;
Z[10]=q; Z[12]=w; Z[14]=e; Z[15]=a;
Z[16]=m; Z[19]=k; Z[21]=b; Z[25]=p;Z[26]=d; Z[27]=o;
++count; writeSquare(Z, wfp);
if (++pcount == 1000000)
{printf("count %lu\n", count);
pcount = 0; fflush(wfp);}}
v.used[Z[34]] = false;}
v.used[Z[22]] = false;}
v.used[k] = false;}}
v.used[m] = false;
v.used[Z[13]] = false;}}
v.used[f] = false;
v.used[Z[4]] = false;}}
v.used[g] = false;
v.used[Z[17]] = false;v.used[Z[23]] = false;
v.used[Z[32]] = false;}}
v.used[d] = false;
v.used[Z[29]] = false;}}
v.used[n] = false;
v.used[Z[11]] = false;}}
v.used[h] = false;
v.used[Z[28]] = false;}}
v.used[q] = false;
v.used[Z[5]] = false;
v.used[Z[35]] = false;}}
v.used[p] = false;}}
International Journal of Digital Information and Wireless Communications (IJDIWC) 1(4): 733-745The Society of Digital Information and Wireless Communications, 2011(ISSN 2225-658X)
743
8/12/2019 SPECIAL MAGIC SQUARES OF ORDER SIX AND EIGHT
12/13
v.used[w] = false;
v.used[Z[30]] = false;}}
v.used[z] = false;
v.used[Z[24]] = false;}}v.used[o] = false;
v.used[Z[33]] = false;}}
v.used[j] = false;}}
v.used[x] = false;
v.used[Z[18]] = false;}}
v.used[t] = false;}}
printf("number of squares %d\n",
count);return count;}
void get_rest_of_line(int c) {
if (c != '\n') do { c = getchar(); }
while (c != '\n');}
void get_abe(int *a, int *b, int *e)
{
int unused = scanf("%d %d %d", a, b,e);
int c = getchar();
get_rest_of_line(c);}
void getNumPatterns(int *num)
{int unused = scanf("%d", num);
int c = getchar();
get_rest_of_line(c);}
bool check_abe(int a, int b, int e)
{bool rv = true;
if ((a NN)|| (b NN)||(e NN))
{
printf("\aValue range is 1 to%d.\n\n", NN);rv = false;}
return rv;}
bool checkNum(int num) {
bool rv = true;if (num
8/12/2019 SPECIAL MAGIC SQUARES OF ORDER SIX AND EIGHT
13/13
if (wfpc != NULL) { time_t startTime
= time(NULL);
int patterns = getSquares(a, b, e,
num, wfpc);int elapsed_t = (int)(time(NULL) -
startTime);
int hr = elapsed_t/3600; elapsed_t %=
3600;
{ int min = elapsed_t/60, sec =
elapsed_t%60;
{ char *fmt = "\na, b, e patterns: %d
elapsed time: %d:%02d:%02d\n";
printf(fmt, patterns, hr, min, sec);
fprintf(wfpc, fmt, patterns, hr, min,
sec);
fclose(wfpc); } } } }} { int unused =
getchar(); } return 0;}
8 References
[1] Al-Ashhab, S.: Magic Squares 5x5, the internationaljournal of applied science and computations, Vol. 15,
No.1, pages 53-64 (2008).
[2] Ahmed, M.: Algebraic Combinatorics of Magic
Squares , Ph.D. Thesis, University Of California (2004).
[3] Ahmed, M.: How Many Squares Are There, Mr.
Franklin?: Constructing and Enumerating Franklin
Squares, American Mathematical Monthly 111, pages
394410 (2004).
[4] Amela, M.: Structured 8 x 8 Franklin Squares,
http://www.region.com.ar/amela/franklinsquares/
[5] Bellew, J.: Counting the Number of Compound and
Nasik Magic Squares, Mathematics Today, pages 111-
118 August (1997).
[6] Benson, W. H.: O. Jacoby, New Recreations With
Magic Squares, Dover, New York (1976).
[7] Besslich, Ph. W.: Comments on Electronic
Techniques for Pictorial Image Reproduction, IEEE
Transactions on Communications 31, pages 846 847(1983).
[8] Besslich, Ph. W.: A Method for the Generation and
processing of Dyadic Indexed Data, IEEE Transactions
on Computers, C-32(5), pages 487 494 (1983).
[9] Diaconis, P., Gamburd, A.: Random Matrices,
Magic Squares and Matching Polynomials, The
Electronic Journal of Combinatorics, Vol. 11, No. 2,
pp. 1 -- 26 (2004).
[10] Ollerenshaw, K., Bre, D. S., Most-perfectPandiagonal Magic Squares: Their Construction and
Enumeration, The Institute of Mathematics And its
Applications, Southend-on-Sea, U.K., (1998).[11] McClintock, E.: On the Most Perfect Forms of
Magic Squares, with Methods for Their Production,
American Journal of Mathematics 19, pages 99120
(1897).
[12] Kolman, B.: Introductory Linear Algebra with
Applications, 3rd edition (1991).
[13] Van den Essen, A.: Magic squares and linear
algebra, American Mathematical Monthly 97, pp. 60-62
(1990).
[14] Walter Trump, www.trump.de/magic-squares
9 Acknowledgment Thanks are due to Harry
White from Canada, who has made great
contributions by developing the code (email:[email protected]).
International Journal of Digital Information and Wireless Communications (IJDIWC) 1(4): 733-745The Society of Digital Information and Wireless Communications, 2011(ISSN 2225-658X)
745