# A curious 5x5 square

Can you fill a 5x5 grid with numbers from 1 to 5, such that every number occurs exactly once in each row, exactly once in each column and exactly once in each broken diagonal (in both directions)? Note that a broken diagonal is a diagonal line that wraps around the boundaries of the square: https://en.wikipedia.org/wiki/Broken_diagonal

Good luck!

• It seems much clearer to call that "wraparound diagonal". ("Broken diagonal" sounds like the opposite: the non-wrapped-around subset of the diagonal)
– smci
Oct 7, 2019 at 21:37

I think the following would work

1 2 3 4 5
3 4 5 1 2
5 1 2 3 4
2 3 4 5 1
4 5 1 2 3

Strategy

The first row is

12345
and each subsequent row is the previous row cyclically rotated two places.

• No way, you did that almost instantly! That is insane speed. It won't even let me accept the answer yet. Oct 7, 2019 at 10:56
• I was about to post this too. I think this is essentially the only solution, up to permuting the digit values, and reflection. Oct 7, 2019 at 10:57
• By the way, I think this method works to fill any NxN square with N numbers, as long as N is coprime to 6. Oct 7, 2019 at 12:00
• @DmitryKamenetsky: Yes, it works for 25 too. Assume the top row is in numerical order. One set of diagonals has the numbers in the same order as the top row, and on the other set of diagonals they go in steps of 3. Since 3 is coprime to 25, they also contain all the numbers exactly once. Oct 7, 2019 at 13:09
• @DmitryKamenetsky And if you use a different row offset than 2, say k, then the diagonals go in steps of k-1 and k+1, and the columns in steps of k. To have all different numbers in the columns and diagonals, you then need k-1, k, and k+1 to be coprime to N. That doesn't help with N that are multiples of 2 or 3, so you might as well stick with the row offset of 2. Oct 7, 2019 at 13:13