Embercode
✕
ArraysQuick quiz

Matrix moves

8 questions. Covers Spiral traversal of a Python grid.

Questions 1 to 5 of 8

  1. 1. What does this program print? ``python grid = [[1, 2], [3, 4]] n = len(grid) for i in range(n): for j in range(i + 1, n): grid[i][j], grid[j][i] = grid[j][i], grid[i][j] grid.reverse() print(grid) ``
  2. 2. Put the steps of the shape test from the lesson in order.

    Use the arrows to put the steps in order.

    1. 1.Run spiral on the grid to get the visiting order
    2. 2.Sort the visited values with sorted() and compare them with 1, 2, 3 and so on
    3. 3.Count the shapes whose check passes and print the total
    4. 4.Fill a grid of rows by cols with the values r * cols + c + 1
  3. 3. For a 5 by 5 grid, one clockwise turn is applied. The value at row 0, column 0 moves to which position?
  4. 4. What does this program print? ``python grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] n = len(grid) for i in range(n): for j in range(n): grid[i][j], grid[j][i] = grid[j][i], grid[i][j] print(grid[0]) ``
  5. 5. In the 4 by 4 spiral fill from the lesson, the values 1 to 16 go around the grid in a spiral. What number is in row 1, column 0? Type the number.

    Type your answer.

4 question(s) left on this page.

Typed answers ignore extra spaces and, for most questions, capital letters.