Published
Edited
Dec 9, 2021
3 stars
Insert cell
Insert cell
Insert cell
generations = {
const generations = [];
for (const n of run(data, 256)) {
generations.push(n);
yield generations;
}
}
Insert cell
part2 = run(data, 256)
Insert cell
part1 = run(data, 80)
Insert cell
function* run(data, n) {
while (n--) {
data = step(data);
yield _.sum(Object.values(data));
}
}
Insert cell
step = (fishes) => {
const next = {};
for (const [n, count] of Object.entries(fishes)) {
if (n > 0) {
next[n - 1] = (next[n - 1] || 0) + count;
} else {
next[6] = (next[6] || 0) + count;
next[8] = (next[8] || 0) + count;
}
}
return next;
}
Insert cell
data = _.countBy((which === "test" ? test : input).trim().split(","))
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