Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
♞ hope hope reiter ... (vigesimal transformation) solution in Clear category for [old] The Shortest Knight's Path by vincent.tscherter
"use strict";
function knightPath(cells) {
let createMoves = pos => [-18, 22, 41, 39, 18, -22, -41, -39]
.map(p => (parseInt(pos, 20) + p).toString(20))
.filter(p => p.match(/[a-h][1-8]/)),
[start, target] = cells.split('-'),
current = createMoves(start),
counter = 1;
while (!current.includes(target)) {
current = current.reduce((accu, pos) =>
accu.concat(createMoves(pos)), current)
.filter((x, i, a) => a.indexOf(x) == i);
counter++
}
return counter
}
var assert = require('assert');
if (!global.is_checking) {
// These "asserts" are used for self-checking and not for an auto-testing
assert.equal(knightPath("b1-d5"), 2)
assert.equal(knightPath("a6-b8"), 1)
assert.equal(knightPath("h1-g2"), 4)
assert.equal(knightPath("h8-d7"), 3)
assert.equal(knightPath("a1-h8"), 6)
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
July 11, 2018
Comments: