Skip to content

Instantly share code, notes, and snippets.

@ldco2016
Created November 12, 2017 22:18
Show Gist options
  • Save ldco2016/a8e2c10cf510f2fb34e277e6efd3ea96 to your computer and use it in GitHub Desktop.
Save ldco2016/a8e2c10cf510f2fb34e277e6efd3ea96 to your computer and use it in GitHub Desktop.
function main() {
var n = parseInt(readLine());
var a = [];
for(a_i = 0; a_i < n; a_i++){
a[a_i] = readLine().split(' ');
a[a_i] = a[a_i].map(Number);
}
let sumPrimaryDiagonal = sumSecondaryDiagonal = 0;
for (i = 0, len = a.length; i < len; i++) {
let line = a[i];
sumPrimaryDiagonal += line[i];
sumSecondaryDiagonal += line[(len -1) - i];
}
console.log(Math.abs(sumPrimaryDiagonal - sumSecondaryDiagonal))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment