Public
Edited
Dec 5, 2022
1 fork
1 star
Insert cell
Insert cell
Insert cell
d3.sum(
input0.split("\n").map(
(sack) =>
sack
.match(new RegExp(".{1," + sack.length / 2 + "}", "g"))
.map((compartment) => new Set(compartment.split("")))
.reduce((a, b) => code.indexOf([...d3.intersection(a, b)][0])) + 1
)
)
Insert cell
d3.sum(
input1.split("\n").map(
(sack) =>
sack
.match(new RegExp(".{1," + sack.length / 2 + "}", "g"))
.map((compartment) => compartment.split(""))
.reduce((a, b) => code.indexOf([...d3.intersection(a, b)][0])) + 1
)
)
Insert cell
Insert cell
{
const input = input0.split("\n");
return d3.sum(
[...Array(Math.ceil(input.length / 3))]
.map((_) => input.splice(0, 3).map((sack) => sack.split("")))
.map((d) => code.indexOf([...d3.intersection(...d)][0]) + 1)
);
}
Insert cell
{
const input = input1.split("\n");
return d3.sum(
[...Array(Math.ceil(input.length / 3))]
.map((_) => input.splice(0, 3).map((sack) => sack.split("")))
.map((d) => code.indexOf([...d3.intersection(...d)][0]) + 1)
);
}
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