Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Humpty Dumpty Form by kurosawa4434
"use strict";
function spheroid(height, width) {
const a = width / 2;
const b = height / 2;
const v = 4 * Math.PI * a**2 * b / 3;
let s = 0;
if (height > width) {
const e = Math.sqrt(1 - (a / b)**2);
s = 2 * Math.PI * a**2 * (1 + (b / (a*e)) * Math.asin(e));
} else if (height < width) {
const e = Math.sqrt(1 - (b / a)**2);
s = 2 * Math.PI * (a**2 + b**2 * Math.atanh(e) / e);
} else {
s = 4 * Math.PI * a**2;
}
return [v, s].map(x=>Math.round(x*100)/100);
}
var assert = require('assert');
if (!global.is_checking) {
// These "asserts" are used for self-checking and not for an auto-testing
assert.deepEqual(spheroid(4, 2), [8.38, 21.48])
assert.deepEqual(spheroid(2, 2), [4.19, 12.57])
assert.deepEqual(spheroid(2, 4), [16.76, 34.69])
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
Aug. 17, 2018
Comments: