I need to traverse a matrix on diagonals as in the following example. I tried to adapt the code from Traverse Matrix in Diagonal strips but I didnt succed.
Its a matrix of ints: int M[n][n];
order of diagonals to traverse:
- d(0)
- d(+1)
- d(-1)
- d(+2)
- d(-2)
- d(+3)
- d(-3) and so on
lets take this example:
00 01 02 03
10 11 12 13
20 21 22 23
30 31 32 33
so the output required will be:
slice 1: 00 11 22 33
slice 2: 01 12 23
slice 3: 10 21 32
slice 4: 02 13
slice 5: 20 31
slice 6 : 03
slice 7: 30