MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / make_matrix

Function make_matrix

matrix/rotate_matrix.py:11–25  ·  view source on GitHub ↗

>>> 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

(row_size: int = 4)

Source from the content-addressed store, hash-verified

9
10
11def make_matrix(row_size: int = 4) -> list[list[int]]:
12 """
13 >>> make_matrix()
14 [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
15 >>> make_matrix(1)
16 [[1]]
17 >>> make_matrix(-2)
18 [[1, 2], [3, 4]]
19 >>> make_matrix(3)
20 [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
21 >>> make_matrix() == make_matrix(4)
22 True
23 """
24 row_size = abs(row_size) or 4
25 return [[1 + x + y * row_size for x in range(row_size)] for y in range(row_size)]
26
27
28def rotate_90(matrix: list[list[int]]) -> list[list[int]]:

Callers 1

rotate_matrix.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected