1

I have a 2D array (StartingArray) NxN (for example 3x3). I would like my 2 other arrays (LRotateArray and RRotateArray) to be StartingArray rotated by 45 degrees left and right (each line in LRotateArray and RRotateArray are diagonals in StartingArray):

StartingArray:
1 2 3
4 5 6
7 8 9

LRotateArray:
1
4 2
7 5 3
8 6
9

RRotateArray:
7
4 8
1 5 9 
2 6
3

I want to edit LRotateArray and RRotateArray while getting input to StartingArray.

I found a formula allowing me to generate LRotateArray:

if StartingArray[i][j]=k then L_j=i+j
if j>(N-1-i) then  L_i=N-i-j else L_i=i
LRotateArray[L_i][L_j]=k

Is there any easy way to transform LRotateArray into RRotateArray, or do I have to find another formula like the one above?

1
  • Getting RRotateArray from the StartingArray is a lot easier than getting it from LRotateArray. So I suggest you find another formula for this. However regarding your current formula, I have no idea how it would work and some of it (L_i=N=i-j) just does not make any sense at all. Commented Nov 19, 2013 at 12:20

1 Answer 1

1

IMHO building RRotateArray from StartingArray is easier than building it from LRotateArray. This is how I would implement both rotations:

for Row := 0 to N - 1 do
begin
  for Col := 0 to N - 1 do
  begin
    LeftRow := Col + Row;
    LeftCol := Min(Col, N - 1 - Row);
    LRotateArray[LeftCol, LeftRow] := StartingArray [Col, Row];

    RightRow := Col + (N - Row - 1);
    RightCol := Min(Col, Row);
    RRotateArray[RightCol, RightRow] := StartingArray [Col, Row];
  end;
end;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.