Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Compass, Map and Spyglass by Sim0000
"use strict";
function navigation(seaside) {
const d = (c1, c2) => Math.max(Math.abs(pos[c2][0] - pos[c1][0]), Math.abs(pos[c2][1] - pos[c1][1]));
let pos = {};
for(let y in seaside){
for(let x in seaside[0]){
const c = seaside[y][x];
if(c != 0) pos[c] = [y, x];
}
}
return d('Y', 'C') + d('Y', 'M') + d('Y', 'S');
}
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. 10, 2018
Comments: