Public
Edited
Sep 23, 2023
1 fork
1 star
Insert cell
Insert cell
Insert cell
function stepsToExit(offsets, update = (i, offsets) => offsets[i]++) {
let steps = 0;
let i = 0;
while (i >= 0 && i < offsets.length) {
const jmp = offsets[i];
update(i, offsets);
i += jmp;
steps++;
}
return steps;
}
Insert cell
function part1(input) {
return stepsToExit(input.split("\n").map(Number));
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function part2(input) {
const updateFn = (i, offsets) =>
offsets[i] >= 3 ? offsets[i]-- : offsets[i]++;
return stepsToExit(input.split("\n").map(Number), updateFn);
}
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