Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for [old] Counting Tiles by Sim0000
"use strict";
function countingTiles(radius){
n = Math.floor(radius)
r = radius * radius
solid = 0
total = 0
for(y = 0; y <= n; y++){
for(x = 0; x <= n; x++){
if((x + 1) * (x + 1) + (y + 1) * (y + 1) <= r) solid++
if(x * x + y * y < r) total++
}
}
return [4 * solid, 4 * (total - solid)]
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(countingTiles(2).toString(), [4, 12].toString(), "N=2");
assert.equal(countingTiles(3).toString(), [16, 20].toString(), "N=3");
assert.equal(countingTiles(2.1).toString(), [4, 20].toString(), "N=2.1");
assert.equal(countingTiles(2.5).toString(), [12, 20].toString(), "N=2.5");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
July 20, 2016
Comments: