They offered to solve just such a puzzle on matrices.

A square matrix N * N is proposed, where N is an odd number. It is required to "move" clockwise the "insides" of 4 triangles formed when the matrix is ​​divided by the square diagonals.

I can not understand how to approach the problem, what algorithm to follow.

  • Always start with the most naive algorithm, then find how to do it better. - Axenow
  • one
    Make a grid in your mind: a coordinate (0,0) in the center. Then the path of displacements will be: (x,y)->(y,-x)->(-x,-y)->(-y,x)->(x,y) . - AlexGlebe

1 answer 1

Your task is no different from "rotate a square matrix clockwise," all these conditions about diagonals and triangles are introduced to confuse you and only mask the overall picture.

If you at least painted on a piece of paper how and what moves - you would immediately understand that the tasks are the same.

Well, turning the matrix clockwise is such a tricky task that it is searched for once.

Small hint: a matrix rotated 90 degrees is a matrix in which x and y are interchanged.

There are even implementations on stackoverflow, see for example starting from here: