Public
Edited
Dec 4, 2022
1 fork
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
testInventories = parseInventories(test)
Insert cell
function parseInventories(input) {
return input.split("\n\n").map((elf, id) => {
const calories = elf.split("\n").map(Number);
return ({id, totalCalories: d3.sum(calories), calories});
});
}
Insert cell
input = FileAttachment("aoc-2022-1.txt").text()
Insert cell
inventories = parseInventories(input)
Insert cell
inventories
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
d3.greatest(inventories, e => e.totalCalories)
Insert cell
Insert cell
topInventories = d3.quickselect(inventories.slice(), 3, undefined, undefined, (a, b) => b.totalCalories - a.totalCalories).slice(0, 3)
Insert cell
d3.sum(topInventories, e => e.totalCalories)
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