Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def print_m(m):
- s = ''
- for i in range(len(m)):
- for j in range(len(m[i])):
- s += str(m[i][j]) + ' '
- s += '\n'
- print(s)
- def rotate(m):
- n = len(m)
- c = int((n + 1) / 2)
- f = int(n / 2)
- for x in range(c):
- for y in range(f):
- m[x][y], m[n - 1 - y][x] = m[n - 1 - y][x], m[x][y]
- m[n - 1 - y][x], m[n - 1 - x][n - 1 - y] = m[n - 1 - x][n - 1 - y], m[n - 1 - y][x]
- m[n - 1 - x][n - 1 - y], m[y][n - 1 - x] = m[y][n - 1 - x], m[n - 1 - x][n - 1 - y]
- return m
- if __name__ == "__main__":
- a = [[1, 2], [3, 4]]
- print_m(rotate(a))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement