Public
Edited
Dec 1, 2023
Insert cell
Insert cell
Insert cell
function parse(input) {
const regex = /(\d+)/g;
return input.split("\n").map((line) => {
const numbers = Array.from(line.matchAll(regex), (m) => Number(m[0]));
return {
dSize: numbers[1],
initPos: numbers[3]
};
});
}
Insert cell
Insert cell
function dropTime(discs) {
const n = discs.map((d) => d.dSize);
const a = discs.map((d, i) => -(i + 1) - d.initPos);
return AOC.chineseRemainderTheorem(n, a);
}
Insert cell
function part1(input) {
return dropTime(parse(input));
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function part2(input) {
return dropTime([...parse(input), { dSize: 11, initPos: 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