Skip to content

Instantly share code, notes, and snippets.

@ana0
Created July 16, 2014 17:06
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/352cd80472afe699faec to your computer and use it in GitHub Desktop.
Save ana0/352cd80472afe699faec to your computer and use it in GitHub Desktop.
def clockwise_rotation(grid):
#returns a representation of the grid rotated clockwise
rotated = [["" for i in grid] for i in grid]
l = len(grid)
for r in range(l):
x = l - r
for c in range(l):
rotated[r][c] = grid[x-1][r]
return rotated
def counterclockwise_rotation(grid):
#returns a representation of what you'd get if you rotated the grid 90 degress counterclockwise
rotated = [["" for i in grid] for i in grid]
l = len(grid)
for r in range(l):
for c in range(l):
x = l - r
rotated[r][c] = grid[c][x-1]
return rotated
def horizontal_flip(grid):
#returns a representation of what you'd get if you flipped the grid horizontally
rotated = [["" for i in grid] for i in grid]
l = len(grid)
for r in range(l):
for c in range(l):
x = l - c
rotated[r][c] = grid[c][x-1]
return rotated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment