Perl Weekly Challenge 053: Rotate Matrix and Vowel Strings
Rotate Matrix
Write a script to rotate the following matrix by given 90/180/270 degrees clockwise.[ 1, 2, 3 ] [ 4, 5, 6 ] [ 7, 8, 9 ]For example, if you rotate by 90 degrees then expected result should be like below
[ 7, 4, 1 ] [ 8, 5, 2 ] [ 9, 6, 3 ]
The easiest way to work with multidimensional data in Perl is PDL. Interestingly, I haven’t found a direct method to rotate a matrix in this way.
What I have found, though, was a method to transpose a matrix, which means to switch the columns and rows. The result for the sample input is