I was looking at the Wikipedia page on magic squares, which gave the following equation to generate the numbers for a given square:
$$n \left( \left( i + j - 1 + \frac{n}{2} \right) \mod n \right) + \left( \left(i + 2j - 2 \right) \mod n \right) + 1$$
where $i$ and $j$ are rows and columns. However, it doesn't seem to generate the correct numbers.
For example, for a $3 \times 3$ magic square, the first element should be $8$, but if I plug in $i=1$, $j=1$, $n=3$ into the equation, I get $9.5$. What's the deal?
There should be $\lfloor\frac{n}{2}\rfloor=\lfloor\frac{3}{2}\rfloor=1$, not $\frac{n}{2}$
http://en.wikipedia.org/wiki/Floor_and_ceiling_functions