Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear&Readable solution in Clear category for [old] Counting Tiles by SaintDron
"use strict";
function countingTiles(radius){
let range = Math.ceil(radius),
allCount = Math.pow(range, 2), // 1/4 sector
clearCount = 0, wholeCount = 0;
for (let i = 0; i < range; i++) {
for (let j = 0; j < range; j++) {
if (Math.pow(radius, 2) < Math.pow(i, 2) + Math.pow(j, 2))
clearCount++;
if (Math.pow(radius, 2) > Math.pow(i + 1, 2) + Math.pow(j + 1, 2))
wholeCount++;
}
}
return [wholeCount * 4, (allCount - wholeCount - clearCount) * 4];
}
var assert = require('assert');
if (!global.is_checking) {
assert.deepEqual(countingTiles(2), [4, 12], "N=2");
assert.deepEqual(countingTiles(3), [16, 20], "N=3");
assert.deepEqual(countingTiles(2.1), [4, 20], "N=2.1");
assert.deepEqual(countingTiles(2.5), [12, 20], "N=2.5");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
March 1, 2018