The matrix tornado is just like any other tornado: it consists of things rotating around a center. In this case, elements of the matrix instead of air.
Here is an example of a matrix tornado:
First we start by sectioning the matrix into square rings, each section consists of elements that are farther away from the border by the same distance. These sections will be rotated clockwise around the center. In real tornadoes, the severity increases towards the center, and so does the rotation step in a matrix tornado: the outermost section (the red one) is rotated by 1 step, the next (the yellow) one is rotated by 2, and so on. A rotation step is a 90° rotation around the center.
Task:
Your task, should you accept it, is to write a function or program that takes as input a square matrix, apply the tornado effect to it and then output the resulting matrix.
Input:
The input should be a square matrix of order n
where n >= 1
. No assumption is to be made about the elements of the matrix, they could be anything.
Output:
A square matrix of the same order which would be the result of applying the tronado effect to the input matrix.
Examples:
A matrix of order n = 1
:
[['Hello']] ===> [['Hello']]
A matrix of order n = 2
:
[[1 , 2], ===> [[5 , 1],
[5 , 0]] [0 , 2]]
A matrix of order n = 5
:
[[A , B , C , D , E], [[+ , 6 , 1 , F , A],
[F , G , H , I , J], [- , 9 , 8 , 7 , B],
[1 , 2 , 3 , 4 , 5], ===> [/ , 4 , 3 , 2 , C],
[6 , 7 , 8 , 9 , 0], [* , I , H , G , D],
[+ , - , / , * , %]] [% , 0 , 5 , J , E]]
;)
\$\endgroup\$