Skip to content

Instantly share code, notes, and snippets.

@ana0
Created July 11, 2014 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ana0/a2dca0394f154a09956e to your computer and use it in GitHub Desktop.
Save ana0/a2dca0394f154a09956e to your computer and use it in GitHub Desktop.
def create_grid(x):
#creates nested set of lists that represent a grid matrix
gridarray = [[i for i in range(x)] for i in range(x)]
return gridarray
def rotate_grid_counterclockwise(grid):
#returns a representation of what you'd get if you rotated the matrix 90 degress counterclockwise
rotated = [["" for i in grid] for i in grid]
x = len(grid)
r = 0
for row in grid:
c = 0
for column in row:
rotated[r][c] = grid[c][x-1]
c += 1
r += 1
x -= 1
return rotated
def print_grid(grid):
#pretty printing for matrices
for i in grid:
print(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment