Platform
Resources
Pricing
Sign in
Get started
Mike Bostock
Visualization toolmaker. Founder @observablehq. Creator @d3. Former @nytgraphics. Pronounced BOSS-tock.
Workspace
Fork
Public
🎄 Advent of Code 2022
By
Mike Bostock
Edited
Dec 4, 2022
1 fork
3 stars
1
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
Filter
Columns
Sort
Slice
Save
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.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
test
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
testInventories
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
parseInventories
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
input
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
inventories
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
Cells
inventories
File attachments
Databases
Filter
Column
Operator
Columns
Sort
Column
Direction
Descending
Ascending
Slice
From
Start
To
End
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
topInventories
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML