import 'dart:io';
int sumDiagonals(List<List<int>>matrix) {
var rows = matrix.length;
var cols = matrix[0].length;
var sumDiagonalLeft = 0;
var sumDiagonalRigth = 0;
for (var i = 0; i < rows; i++) {
sumDiagonalLeft += matrix[i][i];
sumDiagonalRigth += matrix[i][cols - i - 1];
}
print("sumDiagonalLeft = " + sumDiagonalLeft.toString());
print("sumDiagonalRigth = " + sumDiagonalRigth.toString());
return sumDiagonalLeft + sumDiagonalRigth;
}
void main() {
List<List<int>> matrix = [ [1, 2, 3, 4, 0],
[5, 6, 100, 8, 1],
[2, 100, 8, 100, 3],
[1, 7, 100, 9, 6],
[9, 10, 11, 12, 13]];
// sumDiagonalLeft = (1 + 6 + 8 + 9 + 13) = 37
// sumDiagonalRigth = (0 + 8 + 8 + 7 + 9) = 32
// 37 + 32 = 69
stdout.write(sumDiagonals(matrix));
}
/*
run:
sumDiagonalLeft = 37
sumDiagonalRigth = 32
69
*/