5x5 Magic Square

this applet creates a new 5x5 magic square everytime you press generate. the sum of all columns and all rows are the same. (the diagonals are not always the same, though - but see below.) Sorry, your browser is not Java enabled, you will not be able to see the magic square applet.

the algorithm is simple (works with any NxN square if N is odd): start from any cell and travel diagonally counting up to N. (if you end up outside the square anytime during this traversal, "wrap around" to the opposite side as if right connects to left and top connects to bottom.) when you reach N, move one cell orthogonally (ie. left, right, up, down). repeat these actions (diagonal traversal for N cells, orthogonal move for 1 cell) but using the original directions (diagonal, orthogonal) selected at the start.

i've noticed that if you start at the middle of the first row, and travel diagonally north east (to direction of right upper corner) for N cells, then move DOWN one cell and repeat, the magic square will have all columns, rows, and even diagonals add up to the same value.

i'm sure there are tons of "scientific" documents out there on magic squares!