Puzzle 2D14


Puzzle D14 — Rotate the elements of a 2D array

[M-7] Write a function that moves every element of an array down one position in raster order. Element x[i][j] moves to x[i][j-1], unless j is 0. Then it is moved to x[i-1][NUMCOLS-1]. The first element of the array is moved to the last location in the array.

Before:         After:

0 1 2 3 4       1 2 3 4 5
5 6 7 8 9       6 7 8 9 0

The previous testing framework can easily be modified for this puzzle.



Previous Page        Answer         Next Page         Home