Created
July 3, 2014 02:18
-
-
Save octopuscabbage/0d884829e8349c74f0b8 to your computer and use it in GitHub Desktop.
i'm the best mayne i deeeeeeeeeeeeeeeeed it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
matrix_list = [[1,2,3],[4,5,6],[7,8,9]] | |
def lrange(seq): | |
'''returns a generator for the range of a length of a matrix''' | |
return range(len(seq)) | |
def rotateMatrix(matrix_list): | |
'''rotates a matrix''' | |
#Constructs matrix of same size as supplied matrix | |
new_matrix = [[0 for x in lrange(matrix_list[0])] for z in lrange(matrix_list)] | |
x=0 | |
for row in matrix_list: | |
for y in lrange(row): | |
newx,newy = rotateXY(x,y,len(matrix_list)) | |
new_matrix[newx][newy] = matrix_list[x][y] | |
x+=1 | |
return new_matrix | |
def print_matrix(new_matrix): | |
for line in new_matrix: | |
print(line) | |
def rotateXY(x,y,size): | |
'''takes the x y coordinate of a point on matrix of size size and returns | |
the new x y values of the point in a tuple.''' | |
return (y, (size-1) - x) | |
print(rotateMatrix(matrix_list)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment