TASK
The goal is to write a program that rotates any two-dimensional list by 45 degrees, it must be able to do this up to 7*45 (at once) before returning the list. The list will not necessarily be square or rectangular. You must include output for the examples in your answer. It must also work for cases that are not in the examples... circles, triangles etc. You cannot use a pre-existing function to do the whole thing.
All lists will have at least one axis of symmetry (N,S,E,W). All sublists are to be assumed as center-aligned. Odd-even lists will shift to the left one to align properly. See example 4 for gaps in the middle of a sublist.
INPUT
Your program will use a variable named l
containing the list, and a variable named n
specifying the amount the list will be rotated (n*45) (n
will always be less than 7, and can be 0). It will have to accept l
containing sublists of any printable data type (decimal, List, int, String[].. etc), but sublists will only contain one data type at a time.
You do not need to accept console input or use stdin. The lines specifying the test values of l
and n
are not included in the character count, but must be included in the submitted code.
OUTPUT
Your program must print the list in the correct orientation, NIL can be used to pad lists if you desire, but padding is not necessary (you get a smiley face if they are padded, though). Sub-lists do not have to be indented or separated by newlines as in the examples.
EXAMPLES
1
IN
l=
[[0 , 1 , 2],
[3 , 4 , 5],
[6 , 7 , 8]]
n=1
OUT
[ [0],
[3 , 1],
[6 , 4 , 2],
[7 , 5],
[8] ]
2
IN
l=
[[a , b , c , d],
[e , f , g , h]]
n=2
OUT
[[e , a],
[f , b],
[c , g],
[h , d]]
3
IN
l=
[[A , B , C , D , E , F],
[G , H , I , J],
[K , L],
[0 , 8],
[M , N],
[O , P , Q , R],
[S , T , U , V , W , X]]
n=7
OUT
[ [F],
[E],
[D , J],
[C , I],
[B , H , L],
[A , G , K , 8],
[0 , N , R , X],
[M , Q , W],
[P , V],
[O , U],
[T],
[U] ]
4
IN
l=
[[9 , 8 , 7 , 6],
[5],
[4 , 3 , 2 , 1],
[0] ]
n=3
OUT
[ [0 , 4],
[3],
[2 , 5 , 9],
[1 ,NIL, 8],
[7],
[6], ]
5
IN
l=
[ [Q],
[X ,NIL, Y],
[Z] ]
n=2
OUT
[ [X],
[Z ,NIL, Q],
[Y] ]
n
times and not byn
·45 °? I am asking because I am pretty certain that I would not obtain the result of example 3 by applying seven 45 ° rotations. \$\endgroup\$