Published
Edited
Jan 21, 2022
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Math.log(10000)
Insert cell
Insert cell
lowerBound = 1e4
Insert cell
upperBound = 1e5
Insert cell
avgGap = (Math.log(lowerBound) + Math.log(upperBound)) / 2
Insert cell
Insert cell
Insert cell
Insert cell
nCandidates = (upperBound - lowerBound)
Insert cell
Insert cell
nPrimes = nCandidates / avgGap
Insert cell
Insert cell
pctEstimate = nPrimes / nCandidates
Insert cell
Insert cell
// https://stackoverflow.com/a/40200710/120290
isPrime = (num) => {
for (let i = 2, s = Math.sqrt(num); i <= s; i++)
if (num % i === 0) return false;
return num > 1;
}
Insert cell
pctActual = {
let prime = 0;
let composite = 0;
for (let i = lowerBound; i < upperBound; i++) {
if (isPrime(i)) {
prime++;
} else {
composite++;
}
if (!(i % 1000) || i === upperBound - 1)
yield [i, (prime / (prime + composite)), prime];
}
}
Insert cell
Insert cell
Insert cell
f = d3.format(".1%")
Insert cell
import {tweet} from "@mbostock/tweet"
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more