Public
Edited
Dec 3
Paused
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function part1(input) {
const regex = /mul\((\d{1,3}),(\d{1,3})\)/g;
return AOC.sum(
[...input.matchAll(regex)].map((d) => Number(d[1]) * Number(d[2]))
);
}
Insert cell
Insert cell
Insert cell
Insert cell
function part2(input) {
const regex = /don't\(\).*?do\(\)|don't\(\).*/g; // Only matches unclosed don't if no matched pair found
return part1(puzzleInput.replaceAll("\n", "").replace(regex, ""));
}
Insert cell
Insert cell
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