I would like to try my hand at creating Magic Square in PHP (i.e. a grid of numbers that all add to the same value), but I really don't know where to start. I know many methods that create a magic square, for example, starting “1” in a fixed position, and then moving in a certain direction with each iteration. But this does not create a truly randomized Magic Square, which I wanted.
I want to be able to generate an N-by-N magic square of N² numbers, where each row and column are combined in N (N² + 1) / 2 (for example, a 5x5 square, where all rows / columns add up to 65 - the diagonals do not matter) .
Can anyone give a starting point? I don’t want anyone to do this work for me, I just need to know how to start such a project?
I know one generator written in Java ( http://www.dr-mikes-math-games-for-kids.com/how-to-make-a-magic-square.html ), but the last Java experience that I had, was more than 10 years ago. I quickly abandoned it. So I really don't understand what this code does. However, I noticed that when you create a new square, it shows numbers 1-25 (for a 5 × 5 square), before quickly creating a new randomized square.
source
share