Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
why using a ⭐ topology? solution in Clear category for [old] Compass, Map and Spyglass by vincent.tscherter
"use strict";
function navigation(map) {
let coords = {}, dist = ([e, f], [k, l]) => Math.max(Math.abs(e - k), Math.abs(f - l));
map.forEach((l, i) => l.forEach((c, j) => c != 0 && (coords[c] = [i, j])));
return ['C','M','S'].reduce((a,c) => a+ dist(coords['Y'], coords[c]), 0);
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example:')
console.log(navigation([['Y', 0, 0, 0, 'C'],
[ 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0],
['M', 0, 0, 0, 'S']]))
// These "asserts" are used for self-checking and not for an auto-testing
assert.equal(navigation([['Y', 0, 0, 0, 'C'],
[ 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0],
['M', 0, 0, 0, 'S']]), 11)
assert.equal(navigation([[ 0, 0, 'C'],
[ 0, 'S', 0],
['M','Y', 0]]), 4)
assert.equal(navigation([[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 'M', 0, 'S', 0],
[ 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 'C', 0, 0, 0],
[ 0, 'Y',0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0]]), 9)
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
Sept. 6, 2018