Public
Edited
Nov 11, 2022
1 star
Insert cell
Insert cell
function toNumber(str) {
return parseInt(str.replaceAll(/[FL]/g, '0').replaceAll(/[BR]/g, '1'), 2);
}
Insert cell
Insert cell
function ids(input) {
return input.split('\n').map(toNumber);
}
Insert cell
function part1(input) {
return Math.max(...ids(input));
}
Insert cell
Insert cell
Insert cell
Insert cell
function part2(input) {
const sortedIds = AOC.sort(ids(input));
for (let i = 1; i < sortedIds.length; i++) {
if (sortedIds[i] - sortedIds[i - 1] > 1) {
return sortedIds[i] - 1;
}
}
return "No gap found";
}
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