27
1
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]]
I think that you want to clarify that the rotations are 90° rotations. – Erik the Outgolfer – 2018-07-31T23:33:56.307
Also, have you taken this challenge from somewhere else? If so, you must provide attribution. – Erik the Outgolfer – 2018-07-31T23:37:21.097
1@EriktheOutgolfer 1) I've clarified that. 2) This challenge is mine. – ibrahim mahrir – 2018-07-31T23:39:09.973
90 degrees clockwise or anti-clockwise? – Giuseppe – 2018-08-01T00:04:01.893
4@Giuseppe Depends on which hemisphere you're in
;)
– Jo King – 2018-08-01T00:05:37.38712
First I'd like to say I think this is a good challenge: nice work! But I'd also like to plug this point because I think your choice to say that it could be any type of data leaves your challenge in an awkward spot. Similarly with your statement about the input being a list of lists, you have restricted the languages that can solve this problem without doing overhead work somewhat. I think the challenge is better if these requirements are relaxed. I hope you continue to post nice challenges like this! :)
– FryAmTheEggman – 2018-08-01T01:43:03.777@FryAmTheEggman Thank you for your input! I've removed that restriction. – ibrahim mahrir – 2018-08-01T10:37:31.243