-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path90_degree
More file actions
23 lines (19 loc) · 747 Bytes
/
Copy path90_degree
File metadata and controls
23 lines (19 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#The matrix must be n*n
def RotatePrint(arr, top_x, top_y, down_x, down_y):
i, step = 0, down_x - top_x
while i < step:
arr[top_x][top_y + i], arr[top_x + i][down_y] = arr[top_x + i][down_y], arr[top_x][top_y + i]
arr[top_x][top_y + i], arr[down_x][down_y - i] = arr[down_x][down_y - i], arr[top_x][top_y + i]
arr[top_x][top_y + i], arr[down_x - i][top_y] = arr[down_x - i][top_y], arr[top_x][top_y + i]
i += 1
l = [[1, 2 ,3], [4, 5, 6], [7, 8, 9]]
if len(l) % 2:
layer = len(l) // 2 + 1
else:
layer = len(l) // 2
top_x, top_y, down_x, down_y = 0, 0, len(l) -1, len(l)- 1
for i in range(layer):
RotatePrint(l, top_x, top_y, down_x, down_y)
top_x, top_y = top_x + 1, top_y + 1
down_x, down_y = down_x - 1, down_y - 1
print(l)