C++ implementation traversing the matrix by diagonals instead of columns.