Created
March 7, 2014 14:52
-
-
Save Visgean/9412877 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
# <nbformat>3.0</nbformat> | |
# <codecell> | |
matrix=[[1,2,3,4,5], | |
[6,7,8,9,10], | |
[11,12,13,14,15], | |
[16,17,18,19,20], | |
[21,22,23,24,25] | |
] | |
matrix_clockwise=[ | |
[21, 16, 11, 6, 1], | |
[22, 17, 12, 7, 2], | |
[23, 18, 13, 8, 3], | |
[24, 19, 14, 9, 4], | |
[25, 20, 15, 10, 5] | |
] | |
matrix_anti_clockwise = [ | |
[5, 10, 15, 20, 25], | |
[4, 9, 14, 19, 24], | |
[3, 8, 13, 18, 23], | |
[2, 7, 12, 17, 22], | |
[1, 6, 11, 16, 21] | |
] | |
# <codecell> | |
rotate_clockwise = lambda matrix: [[matrix[row][column] for row in reversed(range(len(matrix)))] for column in range(len(matrix[0]))] | |
rotate_anti_clockwise = lambda matrix: [[matrix[row][column] for row in range(len(matrix))] for column in reversed(range(len(matrix[0])))] | |
# <codecell> | |
assert rotate_clockwise(matrix) == matrix_clockwise | |
assert rotate_anti_clockwise(matrix) == matrix_anti_clockwise | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment