Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Diagonal means Max solution in Clear category for [old] Compass, Map and Spyglass by oduvan
"use strict";
function navigation(seaside) {
// your code here
const els = {};
seaside.forEach((line, i) => {
line.forEach((sym, j) => {
if (!sym) {
return;
}
els[sym] = [i, j]
});
});
const you = els['Y'];
delete els['Y']
return Object.values(els).reduce((sum, coor) => {
return sum + Math.max(
Math.abs(you[0] - coor[0]),
Math.abs(you[1] - coor[1])
)
}, 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. 8, 2018
Comments: