mirror of
https://github.com/open-thought/reasoning-gym.git
synced 2026-04-19 12:58:07 +00:00
simplify rotate method
This commit is contained in:
parent
767c34297f
commit
08d39bca81
1 changed files with 5 additions and 11 deletions
|
|
@ -60,22 +60,16 @@ class RotateMatrixDataset(ProceduralDataset):
|
|||
matrix = [numbers[i * n : (i + 1) * n] for i in range(n)]
|
||||
return matrix
|
||||
|
||||
def _rot90(self, matrix: list[list[int]]) -> list[list[int]]:
|
||||
"""quarter clockwise rotation"""
|
||||
return [list(row) for row in zip(*matrix[::-1])]
|
||||
|
||||
def _get_rotated(self, matrix: list[list[int]], num_rotations: int) -> list[list[int]]:
|
||||
"""Rotate the matrix K times by 90 degrees clockwise"""
|
||||
num_rotations %= 4
|
||||
n = len(matrix)
|
||||
output = deepcopy(matrix)
|
||||
|
||||
for _ in range(num_rotations):
|
||||
for l in range(n // 2):
|
||||
for i in range(l, n - 1 - l):
|
||||
(output[l][i], output[i][n - 1 - l], output[n - 1 - l][n - 1 - i], output[n - 1 - i][l]) = (
|
||||
output[n - 1 - i][l],
|
||||
output[l][i],
|
||||
output[i][n - 1 - l],
|
||||
output[n - 1 - l][n - 1 - i],
|
||||
)
|
||||
|
||||
output = self._rot90(output)
|
||||
return output
|
||||
|
||||
def _matrix_to_str(self, matrix: list[list[int]]) -> str:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue