Published
Edited
Sep 1, 2020
8 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
min = -5000;
Insert cell
max = 5000;
Insert cell
triples = {
const out = [];
for (let a = min; a <= max; a++){
for (let b = min; b <= max; b++){
const c = Math.sqrt(a ** 2 + b ** 2);
if (a && b && Number.isInteger(c) && Math.abs(gcd(a, b)) === 1) out.push({a, b, c});
}
}
return out;
}
Insert cell
frequency = arr.unique(triples, d => d.a).map(a => {
return {
a,
count: triples.filter(d => d.a === a).length
}
})
Insert cell
fy = d3.scaleLinear()
.domain([0, d3.max(frequency, d => d.count)])
.range([chartHeight, 0]);
Insert cell
function gcd(a, b) {
if (!b) {
return a;
}
return gcd(b, a % b);
}
Insert cell
Insert cell
style = `
circle.triple {
fill: tomato;
}
.axis .domain {
display: none;
}
.grid .domain {
display: none;
}
.grid text {
display: none;
}
.grid line {
stroke: #ddd;
shape-rendering: crispEdges;
}
`
Insert cell
Insert cell
x = d3.scaleLinear()
.domain([min, max])
.range([0, chartWidth]);
Insert cell
y = d3.scaleLinear()
.domain([min, max])
.range([chartHeight, 0]);
Insert cell
Insert cell
margin = ({left: 40, right: 10, top: 10, bottom: 40});
Insert cell
size = Math.min(width, 800);
Insert cell
chartWidth = size - margin.left - margin.right;
Insert cell
chartHeight = size - margin.top - margin.bottom;
Insert cell
Insert cell
arr = require("arraygeous");
Insert cell
d3 = require("d3@6");
Insert cell
import { toc } from "@harrystevens/toc";
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