# 4x4 Magic Square Solver

## Overview

There are many more properties to a magic square than what I have found documented.

the known basics are that for a 4x4, the center square and all other 2x2 squares add up the the magic constant. also, each row adds up the magic constant and each column adds up to the magic constant, and each diagonal adds up to the magic constant. this is the kind of information you can find on wikipedia and elsewhere.

but I have found properties beyond this more intriguing. most or all of them I came up with on my own, plus a few extras which have not completely worked out so I had to toss them. try these and see! I like to tinker with numbers once in a while, and this was a pasttime in a phase of mine. so then I set out to write a solver in DHTML+JavaScript.

given the following layout, we will proceed to examine equations:

```a b c d
e f g h
i j k l
m n o p
```

## centerboxes

each of these funny boxes adds up to the magic constant.

```up center
- b c -
- - - -
- - - -
- n o -
b+c+n+o=magic_constant

left center
- - - -
e - - h
i - - l
- - - -
e+h+i+l=magic_constant
```

## squares

each of these squares adds up to the magic constant.

```upper left
a b - -
e f - -
- - - -
- - - -
a+b+e+f=magic_constant

upper right
- - c d
- - g h
- - - -
- - - -
c+d+g+h=magic_constant

lower left
- - - -
- - - -
i j - -
m n - -
i+j+m+n=magic_constant

lower right
- - - -
- - - -
- - k l
- - o p
k+l+o+p=magic_constant

center
- - - -
- f g -
- j k -
- - - -
f+g+j+k=magic_constant
```

## meshes

these meshes add up to the magic constant.

```upper left
a - c -
- - - -
i - k -
- - - -
a+c+i+k=magic_constant

upper right
- b - d
- - - -
- j - l
- - - -
b+d+j+l=magic_constant

lower left
- - - -
e - g -
- - - -
m - o -
e+g+m+o=magic_constant

lower right
- - - -
- f - h
- - - -
- n - p
f+h+n+p=magic_constant
```

## corners

the corners add up to the magic constant.

```corners
a - - d
- - - -
- - - -
m - - p
a+d+m+p=magic_constant
```

## diagonals

these add up to the magic constant.

```a - - -
- f - -
- - k -
- - - p
a+f+k+p=magic_constant

- - - d
- - g -
- j - -
m - - -
m+j+g+d=magic_constant
```

## rows

each row adds to the magic constant.

```a b c d
- - - -
- - - -
- - - -
a+b+c+d=magic_constant

- - - -
e f g h
- - - -
- - - -
e+f+g+h=magic_constant

- - - -
- - - -
i j k l
- - - -
i+j+k+l=magic_constant

- - - -
- - - -
- - - -
m n o p
m+n+o+p=magic_constant
```

## columns

each column adds up to the magic constant.

```a - - -
e - - -
i - - -
m - - -
a+e+i+m=magic_constant

- b - -
- f - -
- j - -
- n - -
b+f+j+n=magic_constant

- - c -
- - g -
- - k -
- - o -
c+g+k+o=magic_constant

- - - d
- - - h
- - - l
- - - p
d+h+l+p=magic_constant
```

## cornerdiagonals

corner diagonals also add up to the magic constant.

```- - c -
- - - h
i - - -
- n - -
c+h+i+n=magic_constant

- b - -
e - - -
- - - l
- - o -
e+b+o+l=magic_constant
```

## balancedsums

```- - c d
e f - -
- - - -
- - - -
c+d=e+f OR c=e+f-d OR d=e+f-c OR e=c+d-f OR f=c+d-e

- - - -
- - - -
i j - -
- - o p
i+j=o+p OR i=o+p-j OR j=o+p-i OR o=i+j-p OR p=i+j-o

a b - -
- - g h
- - - -
- - - -
a+b=g+h OR a=g+h-b OR b=g+h-a OR g=a+b-h OR h=a+b-g

- - - -
- - - -
- - k l
m n - -
m+n=k+l OR m=k+l-n OR n=k+l-m OR k=m+n-l OR l=m+n-k

- b - -
- f - -
i - - -
m - - -
b+f=i+m OR b=i+m-f OR f=i+m-b OR i=b+f-m OR m=b+f-i

- - c -
- - g -
- - - l
- - - p
c+g=l+p OR c=l+p-g OR g=l+p-c OR l=c+g-p OR p=c+g-l

a - - -
e - - -
- j - -
- n - -
a+e=j+n OR a=j+n-e OR e=j+n-a OR j=a+e-n OR n=a+e-j

- - - d
- - - h
- - k -
- - o -
d+h=k+o OR d=k+o-h OR h=k+o-d OR k=d+h-o OR o=d+h-k

solve 4 situations of sums,    B
B
A
A
a - - -
- f - -
- - - l
- - o -
a+f=o+l OR a=o+l-f OR f=o+l-a OR o=a+f-l OR l=a+f-o

- - c -
- - - h
- j - -
m - - -
m+j=c+h OR m=c+h-j OR j=c+h-m OR c=m+j-h OR h=m+j-c

- - - d
- - g -
i - - -
- n - -
d+g=i+n OR d=i+n-g OR g=i+n-d OR i=d+g-n OR n=d+g-i

- b - -
e - - -
- - k -
- - - p
p+k=b+e OR p=b+e-k OR k=b+e-p OR b=p+k-e OR e=p+k-b

solve 4 situations of sums

- - c -
- f - -
- j - -
- - o -
f+j=c+o OR f=c+o-j OR j=c+o-f OR c=f+j-o OR o=f+j-c

- b - -
- - g -
- - k -
- n - -
g+k=b+n OR g=b+n-k OR k=b+n-g OR b=g+k-n OR n=g+k-b

- - - -
- f g -
i - - l
- - - -
f+g=i+l OR f=i+l-g OR g=i+l-f OR i=f+g-l OR l=f+g-i

- - - -
e - - h
- j k -
- - - -
j+k=e+h OR j=e+h-k OR k=e+h-j OR e=j+k-h OR h=j+k-e

solve 2 situations of sums,    A
B
B
A
- b - -
- - - h
i - - -
- - o -
b+o=h+i OR b=h+i-o OR o=h+i-b OR h=b+o-i OR i=b+o-h

- - c -
e - - -
- - - l
- n - -
c+n=e+l OR c=e+l-n OR n=e+l-c OR e=c+n-l OR l=c+n-e

solve 4 situations of sums,

a - - d
- - - -
- - - -
- n o -
a+d=n+o OR a=n+o-d OR d=n+o-a OR n=a+d-o OR o=a+d-n

a - - -
- - - h
- - - l
m - - -
a+m=h+l OR a=h+l-m OR m=h+l-a OR h=a+m-l OR l=a+m-h

- b c -
- - - -
- - - -
m - - p
b+c=m+p OR b=m+p-c OR c=m+p-b OR m=b+c-p OR p=b+c-m

- - - d
e - - -
i - - -
- - - p
e+i=d+p OR e=d+p-i OR i=d+p-e OR d=e+i-p OR p=e+i-d

solve 2 situations of sums,

- - - d
- f - -
- - k -
m - - -
d+m=f+k OR d=f+k-m OR m=f+k-d OR f=d+m-k OR k=d+m-f

a - - -
- - g -
- j - -
- - - p
a+p=g+j OR a=g+j-p OR p=g+j-a OR g=a+p-j OR j=a+p-g

center sums

- - - -
e f - -  A A
i j - -  B B
- - - -
e+f=i+j OR e=i+j-f OR f=i+j-e OR i=e+f-j OR j=e+f-i

- - - -
- - g h   A A
- - k l   B B
- - - -
g+h=k+l OR g=k+l-h OR h=k+l-g OR k=g+h-l OR l=g+h-k

- b c -   A B
- f g -   A B
- - - -
- - - -
b+c=f+g OR b=f+g-c OR c=f+g-b OR f=b+c-g OR g=b+c-f

- - - -
- - - -
- j k -   A B
- n o -   A B
j+n=k+o OR j=k+o-n OR n=k+o-j OR k=j+n-o OR o=j+n-k

solve 4 situations of sums,

- - c -
- f - -
i - - -
- - - p
f+p=c+i OR f=c+i-p OR p=c+i-f OR c=f+p-i OR i=f+p-c

- b - -
- - g -
- - - l
m - - -
m+g=b+l OR m=b+l-g OR g=b+l-m OR b=m+g-l OR l=m+g-b

a - - -
- - - h
- - k -
- n - -
a+k=h+n OR a=h+n-k OR k=h+n-a OR h=a+k-n OR n=a+k-h

- - - d
e - - -
- j - -
- - o -
d+j=e+o OR d=e+o-j OR j=e+o-d OR e=d+j-o OR o=d+j-e
```

## deriving the magic constant from the list of cell's numbers

this is simple: add them all up, and then divide by 4 (4 rows). it is the same as adding up 1 row which adds up to the magic constant.

$c=\underset{1}{\overset{n}{\Sigma }}\frac{{k}_{n}}{4}$
```for example,
01 02 03 04
29 30 31 32
33 34 35 36
61 62 63 64

c=1+2+3+4 + 29+30+31+32 + 33+34+35+36 + 61+62+63+64=520
c=520/4=130
```

## more properties

More properties can be found at the wikipedia page, though I don't care for its overtones.

```I think you need to throw out a few more of those properties.

Consider this magic square, known to be one that exhibits a particularly
low number of symmetries:

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

Squares: the upper left and lower right squares sum to 32 and the upper
right and lower left squares sum to 36.

Meshes: the upper left and lower right meshes sum to 36 and the upper
right and lower left meshes sum to 32.

Cornerdiagonals: One cornerdiagonal sums to 30 and the other to 38

Balancedsums: sum to various values from 12 to 56
--
Mike Williams
Gentleman of Leisure
```