Skip to content

Instantly share code, notes, and snippets.

@sahid
Created February 17, 2013 19:08
Show Gist options
  • Select an option

  • Save sahid/4972875 to your computer and use it in GitHub Desktop.

Select an option

Save sahid/4972875 to your computer and use it in GitHub Desktop.
Rotate a Matrix N*N to 90 degrees
def rotate(M):
S = len(M)
out = [[0] * S for x in xrange(S)] # create the output matrix
for i in xrange(S):
for j in xrange(S):
out[i][j] = M[S-j-1][i]
return out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment