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!

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

1 Answer 1


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


The first row is

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

  • 1
    $\begingroup$ No way, you did that almost instantly! That is insane speed. It won't even let me accept the answer yet. $\endgroup$ Commented Oct 7, 2019 at 10:56
  • 5
    $\begingroup$ I was about to post this too. I think this is essentially the only solution, up to permuting the digit values, and reflection. $\endgroup$ Commented Oct 7, 2019 at 10:57
  • 2
    $\begingroup$ By the way, I think this method works to fill any NxN square with N numbers, as long as N is coprime to 6. $\endgroup$ Commented Oct 7, 2019 at 12:00
  • 2
    $\begingroup$ @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. $\endgroup$ Commented Oct 7, 2019 at 13:09
  • 2
    $\begingroup$ @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. $\endgroup$ Commented Oct 7, 2019 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.