Rotate the anti-diagonals
CJam, 20
{z_)\zLa+(@+\.+s\,/}
Written as a function block. Try it online
Explanation:
The input can be viewed like this:
That is, we separate the top row and right column from the rest of the matrix, and consider those elements in the order shown by the arrow.
Then the output is like this:
The remaining rectangular block is moved diagonally as a whole, and the edge elements are rearranged in the order/positions showed by the new arrow.
The code does almost exactly that, except the output is first generated with the arrow going straight down (so the matrix has a tail, like the letter P), then corrected.
z zip (transpose) the matrix
_ make a copy
) take out the last row (right column before transposing)
\ swap with the rest of the matrix
z transpose back
La+ append an empty row (needed for the single-column case,
which leaves an empty matrix here)
( take out the first row (top row without the corner)
@+ bring the right column to the top of the stack and concatenate
obtaining an array of the edge elements (marked with the blue arrow)
\ swap with the remaining part (big white block in the diagrams)
.+ concatenate element by element
each edge element is concatenated with a row of the white block
after the white block runs out, the remaining elements form new rows
s convert the whole thing to a string (concatenating all rows)
\ swap with the copy of the transposed matrix
, get its length (number of original columns)
/ split the string into rows of that length
CJam, 44 43 42 40 bytes
qN/:ReeSf.*:sz1fm<{Rz,{(S-(o\}*~]{},No}h
Test it here.
Hmm, much better than my first attempt, but I have a feeling Dennis will solve this in much less anyway...
Input and output are as ASCII grids:
0123
4567
8901
gives
0456
1890
2371
J, 24 char
Function taking one argument.
$$<@(1&|.)/./:&;</.@i.@$
J has an operator /.
called Oblique. It can't invert it, so reconstruction isn't trivial, but you can consider "listing obliques" as a permutation of the elements of the array. So we invert that permutation with /:
(dyadic Sort), by putting the "listing obliques" permutation for that size (</.@i.@$
) on the right and our new oblique values, rotated properly, on the left. Then we reshape this list into the old rectangular array using good old $$
.
3 4$i.10
0 1 2 3
4 5 6 7
8 9 0 1
($$<@(1&|.)/./:&;</.@i.@$) 3 4$i.10
0 4 5 6
1 8 9 0
2 3 7 1
Try it online.