Published
Edited
Dec 7, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
burner = ({linear, progressive})[burnrate]
Insert cell
linear = (a, b) => Math.abs(a - b) // horizontal distance between a and b
Insert cell
progressive = (a, b) => sumOfIntegers(linear(a, b)) // sum of integers between 1 and distance between a and b
Insert cell
// takes number n
// returns the sum of integers between 1 and n
sumOfIntegers = (n) => n * (n + 1) / 2
Insert cell
burn = (burner, data) => {
const extent = d3.extent(data);
const sums = Array.from({length: Math.abs(extent[1] - extent[0])});
return d3.min(sums.map((_, i) => data.reduce((accu, d) => accu + burner(i, d), 0)));
}
Insert cell
fuel = burn(burner, data)
Insert cell
timer(()=>burn(burner,data),100) // takes quite a while; 1000 and higher freezes your browser
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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