Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Three Points Circle by Sim0000
"use strict";
function circle(data) {
let [x1, y1, x2, y2, x3, y3] = data.match(/[0-9]+/g);
// make two line equations
const d = (x, y) => x**2 + y**2
const t21 = [2*(x2 - x1), 2*(y2 - y1), d(x2, y2) - d(x1, y1)];
const t31 = [2*(x3 - x1), 2*(y3 - y1), d(x3, y3) - d(x1, y1)];
// solve systems of equations
const det = (i, j) => t21[i] * t31[j] - t21[j] * t31[i];
const x0 = det(2, 1) / det(0, 1);
const y0 = det(0, 2) / det(0, 1);
// calculate radius
const r = Math.sqrt(d(x1 - x0, y1 - y0));
// return formatted string
const round = x => String(Math.round(100 * x) / 100);
return "(x-" + round(x0) + ")^2+(y-" + round(y0) + ")^2=" + round(r) + "^2";
}
var assert = require('assert');
if (!global.is_checking) {
// These "asserts" are used for self-checking and not for an auto-testing
assert.equal(circle("(2,2),(6,2),(2,6)"), "(x-4)^2+(y-4)^2=2.83^2")
assert.equal(circle("(3,7),(6,9),(9,7)"), "(x-6)^2+(y-5.75)^2=3.25^2")
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
July 20, 2018