Public
Edited
Jul 8, 2024
Paused
Comments locked
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
R = [...compute(pi, Q)]
Insert cell
/*!
* An infinite series that converges quickly on Pi (π) was published by
* the Indian mathematician and astronomer Nilakantha Somayaji (1445-1545)
*
* π = 3 + (4 / 2 * 3 * 4) - (4 / 4 * 5 * 6) + (4 / 6 * 7 * 8) - (4 / 8 * 9 * 10) + …
*/
function* pi() {
function term(input, sign, divisor) {
divisor = input * ++input * ++input;
return (sign * 4) / divisor;
}

let pi = 3;
let i = 1;

while (true) {
let quotient = term(i * 2, i & 1 ? 1 : -1);

pi += quotient;

let reset = yield {
iterations: i++,
term: quotient,
result: pi
};

if (reset) {
pi = 3;
i = 1;
}
}
}
Insert cell
function* compute(series, count = 20) {
for (let value of series()) {
if (--count < 0) break;
yield value;
}
}
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more