-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethods.rb
More file actions
37 lines (27 loc) · 933 Bytes
/
methods.rb
File metadata and controls
37 lines (27 loc) · 933 Bytes
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
26
27
28
29
30
31
32
33
34
35
36
37
matrix = [[1,2,3],[4,5,6],[7,8,9]]
#transpose: switches rows & columns
matrix2 = matrix.transpose
#rotate: simply moves down the first most row(s)
#(it can take in an integer for the number of rows) to the bottom
matrix3 = matrix.rotate
#reverse: swaps the rows
matrix4 = matrix.reverse
#---------------------------------------------------------------------
#rotate 90 degrees means we'll flip the transposed matrix
matrix = [[1,2,3],[4,5,6],[7,8,9]]
def rotate90Deg(matrix)
matrix.reverse.transpose
end
# rotate90Deg(matrix).each {|row| p row}
def reflectMainDiag(matrix)
matrix.transpose
end
# matrix.each {|row| p row}
# puts "---------------"
# reflectMainDiag(matrix).each {|row| p row}
def reflectSecDiag(matrix)
matrix.transpose.reverse.transpose.reverse.transpose
end
# matrix.each {|row| p row}
# puts "---------------"
# reflectSecDiag(matrix).each {|row| p row}