4x4 Magic Square Solver


Enter the numbers you were given in the square. then press the button.

careful: if it's wrong or all are empty, the program will take a while and fail.

This is not server-side-scripting material because of the possibility of endless long loops (to I added a counter that cuts it off after a while of failing) so we're stuck with JavaScript and DHTML.

NOTE: I have found a bug in this program on certain inputs (wish I could remember what they were), where the result causes a cell to become NaN. you can work around it by deleting the contents of that cell and hitting the Solve button again and I believe you get a correct result. I have put in workaround code that replaces the NaN with nothing, which causes the program to continue to solve. It does a much better job, but it flashes a bit.
With 2800 lines of code, it is really difficult to find the line that caused the problem.

This program takes only a few seconds on my computer.

Magic Number Square
(normally it is 34 for a magic square of this size)

If needed, Enter list of cell values to find magic constant. The result will be stored in the Magic Constant above.

The page is GPL'd, with the exception of the tree menu, which is copyright Dynamic Drive. So if you want to take it and expand on my code, go right ahead.