Skip to content

Instantly share code, notes, and snippets.

@djburdick
Created November 17, 2010 05:18
Show Gist options
  • Save djburdick/703012 to your computer and use it in GitHub Desktop.
Save djburdick/703012 to your computer and use it in GitHub Desktop.
playing with gists
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