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

Function move_y

matrix/matrix_based_game.py:196–217  ·  view source on GitHub ↗

Shifts all columns leftward when an entire column becomes empty. >>> move_y([['-', 'A'], ['-', '-'], ['-', 'C']], 2) [['A', '-'], ['-', '-'], ['-', 'C']]

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

Source from the content-addressed store, hash-verified

194
195
196def move_y(matrix_g: list[list[str]], size: int) -> list[list[str]]:
197 """
198 Shifts all columns leftward when an entire column becomes empty.
199
200 >>> move_y([['-', 'A'], ['-', '-'], ['-', 'C']], 2)
201 [['A', '-'], ['-', '-'], ['-', 'C']]
202 """
203
204 empty_columns = []
205
206 for column in range(size - 1, -1, -1):
207 if all(matrix_g[row][column] == "-" for row in range(size)):
208 empty_columns.append(column)
209
210 for column in empty_columns:
211 for col in range(column + 1, size):
212 for row in range(size):
213 matrix_g[row][col - 1] = matrix_g[row][col]
214 for row in range(size):
215 matrix_g[row][-1] = "-"
216
217 return matrix_g
218
219
220def play(

Callers 1

playFunction · 0.85

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected