Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Weak Point by nlupton
"use strict";
function weakPoint(matrix){
let rowTotals = [], colTotals = [];
let rowMin = 0, colMin = 0;
rowTotals = matrix.map( function (row , rowIndex) {
rowIndex === 0 ? colTotals = row :
row.map( function(val , colIndex ) {
colTotals[colIndex] += val;});
return row.reduce( (total , reading) => total += reading);
}) ;
rowMin = Math.min(...rowTotals);
colMin = Math.min(...colTotals);
return [ rowTotals.findIndex(val => val===rowMin) ,
colTotals.findIndex(val => val===colMin) ];
}
var assert = require('assert');
if (!global.is_checking) {
assert.deepEqual(weakPoint([[7, 2, 7, 2, 8],
[2, 9, 4, 1, 7],
[3, 8, 6, 2, 4],
[2, 5, 2, 9, 1],
[6, 6, 5, 4, 5]]
), [3, 3], "Example");
assert.deepEqual(weakPoint([[7, 2, 4, 2, 8],
[2, 8, 1, 1, 7],
[3, 8, 6, 2, 4],
[2, 5, 2, 9, 1],
[6, 6, 5, 4, 5]]
), [1, 2], "Two weak point");
assert.deepEqual(weakPoint([[1, 1, 1],
[1, 1, 1],
[1, 1, 1]]
), [0, 0], "Top left");
}
May 15, 2017
Comments: