Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Indices of minimal elements in arrays of vertical and horizontal sums solution in Clear category for [old] Weak Point by artee2025
"use strict";
function weakPoint(m){
let h = m.map((v, i, ar) => v.reduce((a, b) => a + b));
let v = m.reduce((a, b) => b.map((va, i, ar) => va + a[i]));
let hmin = h.indexOf(Math.min(...h));
let vmin = v.indexOf(Math.min(...v));
return [hmin, vmin]
}
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");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
April 9, 2018
Comments: