Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. def print_m(m):
  2.     s = ''
  3.     for i in range(len(m)):
  4.         for j in range(len(m[i])):
  5.             s += str(m[i][j]) + ' '
  6.         s += '\n'
  7.     print(s)
  8.  
  9.  
  10. def rotate(m):
  11.     n = len(m)
  12.     c = int((n + 1) / 2)
  13.     f = int(n / 2)
  14.     for x in range(c):
  15.         for y in range(f):
  16.             m[x][y], m[n - 1 - y][x] = m[n - 1 - y][x], m[x][y]
  17.             m[n - 1 - y][x], m[n - 1 - x][n - 1 - y] = m[n - 1 - x][n - 1 - y], m[n - 1 - y][x]
  18.             m[n - 1 - x][n - 1 - y], m[y][n - 1 - x] = m[y][n - 1 - x], m[n - 1 - x][n - 1 - y]
  19.     return m
  20.  
  21.  
  22. if __name__ == "__main__":
  23.     a = [[1, 2], [3, 4]]
  24.     print_m(rotate(a))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement