matrix.rotate_matrix

In this problem, we want to rotate the matrix elements by 90, 180, 270 (counterclockwise) Discussion in stackoverflow: https://stackoverflow.com/questions/42519/how-do-you-rotate-a-two-dimensional-array

Attributes

matrix

Functions

make_matrix(→ list[list[int]])

print_matrix(→ None)

reverse_column(→ list[list[int]])

reverse_row(→ list[list[int]])

rotate_180(→ list[list[int]])

rotate_270(→ list[list[int]])

rotate_90(→ list[list[int]])

transpose(→ list[list[int]])

Module Contents

matrix.rotate_matrix.make_matrix(row_size: int = 4) list[list[int]]
>>> make_matrix()
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
>>> make_matrix(1)
[[1]]
>>> make_matrix(-2)
[[1, 2], [3, 4]]
>>> make_matrix(3)
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> make_matrix() == make_matrix(4)
True
matrix.rotate_matrix.print_matrix(matrix: list[list[int]]) None
matrix.rotate_matrix.reverse_column(matrix: list[list[int]]) list[list[int]]
matrix.rotate_matrix.reverse_row(matrix: list[list[int]]) list[list[int]]
matrix.rotate_matrix.rotate_180(matrix: list[list[int]]) list[list[int]]
>>> rotate_180(make_matrix())
[[16, 15, 14, 13], [12, 11, 10, 9], [8, 7, 6, 5], [4, 3, 2, 1]]
>>> rotate_180(make_matrix()) == reverse_column(reverse_row(make_matrix()))
True
matrix.rotate_matrix.rotate_270(matrix: list[list[int]]) list[list[int]]
>>> rotate_270(make_matrix())
[[13, 9, 5, 1], [14, 10, 6, 2], [15, 11, 7, 3], [16, 12, 8, 4]]
>>> rotate_270(make_matrix()) == transpose(reverse_row(make_matrix()))
True
matrix.rotate_matrix.rotate_90(matrix: list[list[int]]) list[list[int]]
>>> rotate_90(make_matrix())
[[4, 8, 12, 16], [3, 7, 11, 15], [2, 6, 10, 14], [1, 5, 9, 13]]
>>> rotate_90(make_matrix()) == transpose(reverse_column(make_matrix()))
True
matrix.rotate_matrix.transpose(matrix: list[list[int]]) list[list[int]]
matrix.rotate_matrix.matrix