Created
November 17, 2010 05:18
-
-
Save djburdick/703012 to your computer and use it in GitHub Desktop.
playing with gists
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
def rotate_matrix(matrix) | |
output = Array.new(matrix.count) { Array.new(matrix.count) } | |
matrix.each_with_index do |mat, i| | |
j = matrix.count - 1 | |
matrix[i].each do |n| | |
output[j][i] = n | |
j -= 1 | |
end | |
end | |
return output | |
end | |
matrix = [] | |
matrix[0] = [1,2,3,4] | |
matrix[1] = [5,6,7,8] | |
matrix[2] = [9,10,11,12] | |
matrix[3] = [13,14,15,16] | |
puts rotate_matrix(matrix).inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment