Public
Edited
Dec 1, 2023
Insert cell
Insert cell
Insert cell
function toDigits(input) {
return input.split("").map(Number);
}
Insert cell
Insert cell
function pairs(xs, offset = 1) {
return AOC.zipWith((a, b) => [a, b], xs, AOC.rotateArray(xs, offset));
}
Insert cell
Insert cell
function part1(input) {
return AOC.sum(
pairs(toDigits(input))
.filter(([a, b]) => a === b)
.map((d) => d[0])
);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function part2(input) {
return AOC.sum(
pairs(toDigits(input), input.length / 2)
.filter(([a, b]) => a === b)
.map((d) => d[0])
);
}
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