Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear&Readable solution in Clear category for [old] Wild Dogs by SaintDron
"use strict";
function wildDogs(coords) {
let equations = {},
maxCount = 0,
result;
coords.forEach((v1, i1) => {
coords.forEach((v2, i2) => {
if (i1 !== i2) {
let k = (v2[1] - v1[1]) / (v2[0] - v1[0]),
b = v1[1] - k * v1[0],
angle = Math.atan2(v1[0], v1[1] - b),
dist = Math.abs(b * Math.sin(angle)),
key = k + "," + b;
equations[key] = ++equations[key] || 1;
if (equations[key] === maxCount && dist < result) {
result = dist;
}
if (equations[key] > maxCount) {
maxCount = equations[key];
result = dist;
}
}
});
});
return Math.round(result * 100) / 100;
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example:')
console.log(wildDogs([[7, 122], [8, 139], [9, 156],
[10, 173], [11, 190], [-100, 1]]))
// These "asserts" are used for self-checking and not for an auto-testing
assert.equal(wildDogs([[7, 122], [8, 139], [9, 156],
[10, 173], [11, 190], [-100, 1]]), 1.13)
assert.equal(wildDogs([[6, -0.5], [3, -5], [1, -20]]), 5.27)
assert.equal(wildDogs([[10, 10], [13, 13], [21, 18]]), 0)
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
Sept. 10, 2018
Comments: