Public
Edited
Dec 22
Paused
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function parse(input) {
return input.split(/\s+/).map((d) => [Number(d), 1]);
}
Insert cell
Insert cell
function countStones(stones, n) {
for (let i = 0; i < n; i++) {
const freqs = new Map();
stones.forEach(([stone, freq]) => {
blink(stone).forEach((newStone) => {
freqs.set(newStone, (freqs.get(newStone) || 0) + freq);
});
});
stones = [...freqs.entries()];
}
return d3.sum(stones, (d) => d[1]);
}
Insert cell
function part1(input) {
return countStones(parse(input), 25);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function part2(input) {
return countStones(parse(input), 75);
}
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