Public
Edited
Dec 8, 2022
1 fork
Importers
1 star
Insert cell
Insert cell
aoc.resultTable(meta)
Insert cell
parse = aoc.lines((l) => {
let match = Array.from(/(\d+)-(\d+),(\d+)-(\d+)/.exec(l), Number);
return { elf1: match.slice(1, 3), elf2: match.slice(3, 5) };
})
Insert cell
fullContains = (a, b) =>
(a[0] <= b[0] && a[1] >= b[1]) || (a[0] >= b[0] && a[1] <= b[1])
Insert cell
contains = (a, x) => a[0] <= x && a[1] >= x
Insert cell
overlaps = (a, b) =>
fullContains(a, b) ||
contains(a, b[0]) ||
contains(a, b[1]) ||
contains(b, a[0]) ||
contains(b, a[1])
Insert cell
function part1(input) {
return input.filter(({ elf1, elf2 }) => fullContains(elf1, elf2)).length;
}
Insert cell
function part2(input) {
return input.filter(({ elf1, elf2 }) => overlaps(elf1, elf2)).length;
}
Insert cell
inputs = ({
test: `2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8`,
real: await FileAttachment("input").text()
})
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