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

Function move_x

matrix/matrix_based_game.py:176–193  ·  view source on GitHub ↗

Simulates gravity in a specific column. >>> move_x([['-', 'A'], ['-', '-'], ['-', 'C']], 1, 2) [['-', '-'], ['-', 'A'], ['-', 'C']]

(matrix_g: list[list[str]], column: int, size: int)

Source from the content-addressed store, hash-verified

174
175
176def move_x(matrix_g: list[list[str]], column: int, size: int) -> list[list[str]]:
177 """
178 Simulates gravity in a specific column.
179
180 >>> move_x([['-', 'A'], ['-', '-'], ['-', 'C']], 1, 2)
181 [['-', '-'], ['-', 'A'], ['-', 'C']]
182 """
183
184 new_list = []
185
186 for row in range(size):
187 if matrix_g[row][column] != "-":
188 new_list.append(matrix_g[row][column])
189 else:
190 new_list.insert(0, matrix_g[row][column])
191 for row in range(size):
192 matrix_g[row][column] = new_list[row]
193 return matrix_g
194
195
196def move_y(matrix_g: list[list[str]], size: int) -> list[list[str]]:

Callers 1

playFunction · 0.85

Calls 2

appendMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected