Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def self.rotate_counterclockwise(matrix)
- # This is where the magic happens
- #pp "Before: #{matrix}"
- n = []
- height = matrix.size
- width = matrix[0].size
- (width - 1).downto(0) { |i|
- line = []
- height.times { |j|
- line << matrix[j][i]
- }
- n << line
- }
- #pp "After: #{n}"
- n
- end
- def self.rotate_clockwise(matrix)
- # This is where the magic happens
- #pp "Before: #{matrix}"
- n = []
- height = matrix.size
- width = matrix[0].size
- width.times { |i|
- line = []
- height.times { |j|
- line << matrix[j][i]
- }
- n << line
- }
- #pp "After: #{n}"
- n
- end
Add Comment
Please, Sign In to add comment