Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Chess Knight by Moff
function chessKnight(start, count) {
const delta = [[1, 2], [2, 1], [2, -1], [1, -2], [-1, -2], [-2, -1], [-2, 1], [-1, 2]];
let moves = (c) => delta.map(([a, b]) => {
let i = String.fromCharCode(c.charCodeAt(0) + a);
let j = parseInt(c[1]) + b;
if ('a' <= i && i <= 'h' && 0 < j && j < 9)
return `${i}${j}`;
}).filter((x) => x);
let res = [];
let temp = [start];
for (let i = 0; i < count; i++) {
let new_res = [];
for (let x of temp) {
for (let y of moves(x))
new_res.push(y);
}
temp = new_res;
for (let x of new_res)
if (!res.includes(x))
res.push(x);
}
let result = [];
for (let c of res)
result.push(c);
result.sort();
return result;
}
May 17, 2018