Public
Edited
Dec 1, 2023
Insert cell
Insert cell
Insert cell
function toRows(input) {
return input.split("\n").map((d) => d.split("\t").map(Number));
}
Insert cell
Insert cell
function part1(input) {
return AOC.sum(
toRows(input)
.map((row) => d3.extent(row))
.map((d) => d[1] - d[0])
);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function divis(nums) {
return AOC.selectLargest(nums).map(([n, ns]) =>
Math.floor(n / ns.filter((x) => n % x === 0)[0])
);
}
Insert cell
Insert cell
function part2(input) {
return AOC.sum(toRows(input).flatMap(divis));
}
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