Quarter turn
Inputs
cells is a grid: a list of 1 to 5 rows, each with the same number (1 to 5) of whole numbers from 0 to 9.
Your tasks
- Create an empty list
turned. - Build one new row for each column
cofcells, from left to right. Walk up the rows from the bottom to the top and take each row'scth number. - Add each new row to
turned. - Complete
rotateRightso it returnsturned. Return it, do not print it.
Example
With cells = [[1, 2, 3], [4, 5, 6]], rotateRight returns [[4, 1], [5, 2], [6, 3]].
Rules
- This turns the grid a quarter turn clockwise.
Test data
TEST DATA 1: cells is [[1, 2, 3], [4, 5, 6]]
TEST DATA 2: cells is [[8]]
Practice focus
Two-dimensional data is a loop over rows with a loop over columns inside. Grids lead straight to flood fill, islands, dynamic programming tables and path problems.