Public
Edited
Dec 2
Paused
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function parse(input) {
return input
.split("\n")
.map((l) => l.split(",").map((r) => r.split("-").map(Number)));
}
Insert cell
Insert cell
function contains([[mn1, mx1], [mn2, mx2]]) {
return (mn1 <= mn2 && mx1 >= mx2) || (mn2 <= mn1 && mx2 >= mx1);
}
Insert cell
Insert cell
function part1(input) {
return parse(input).map(contains).filter(AOC.identity).length;
}
Insert cell
Insert cell
Insert cell
Insert cell
function overlaps([[mn1, mx1], [mn2, mx2]]) {
return !(mx1 < mn2 || mn1 > mx2);
}
Insert cell
function part2(input) {
return parse(input).map(overlaps).filter(AOC.identity).length;
}
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