Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for [old] Berserk Rook by Sim0000
"use strict";
function berserkRook(berserker, enemies) {
n = e = "z"
s = w = "0"
for(r of enemies){
if(r[0] == berserker[0] && r[1] > berserker[1] && r < n) n = r
if(r[0] == berserker[0] && r[1] < berserker[1] && r > s) s = r
if(r[1] == berserker[1] && r[0] > berserker[0] && r < e) e = r
if(r[1] == berserker[1] && r[0] < berserker[0] && r > w) w = r
}
var max = 0
for(r of [n, s, e, w]){
if(r != "0" && r != "z"){
v = berserkRook(r, enemies.filter(e => e != r)) + 1
if(v > max) max = v
}
}
return max
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(berserkRook("c7", ["d5","f7","e6","e7","c5","d6","e5","c6"]), 8, "ex7")
assert.equal(berserkRook('d3', ['d6', 'b6', 'c8', 'g4', 'b8', 'g6']), 5, "First");
assert.equal(berserkRook('a2', ['f6', 'f2', 'a6', 'f8', 'h8', 'h6']), 6, "Second");
assert.equal(berserkRook('a2', ['f6', 'f8', 'f2', 'a6', 'h6']), 4, "Third");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
July 10, 2016