Guest User

Untitled

a guest
Jun 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. def self.rotate_counterclockwise(matrix)
  2. # This is where the magic happens
  3. #pp "Before: #{matrix}"
  4. n = []
  5. height = matrix.size
  6. width = matrix[0].size
  7. (width - 1).downto(0) { |i|
  8. line = []
  9. height.times { |j|
  10. line << matrix[j][i]
  11. }
  12. n << line
  13. }
  14. #pp "After: #{n}"
  15. n
  16. end
  17.  
  18. def self.rotate_clockwise(matrix)
  19. # This is where the magic happens
  20. #pp "Before: #{matrix}"
  21. n = []
  22. height = matrix.size
  23. width = matrix[0].size
  24. width.times { |i|
  25. line = []
  26. height.times { |j|
  27. line << matrix[j][i]
  28. }
  29. n << line
  30. }
  31. #pp "After: #{n}"
  32. n
  33. end
Add Comment
Please, Sign In to add comment