Public
Edited
Oct 2, 2023
1 fork
1 star
Insert cell
Insert cell
function spinlock(steps, iterations) {
let [pos, buffer] = [0, [0]];
for (let i = 1; i <= iterations; i++) {
pos = (pos + steps) % buffer.length;
buffer.splice(pos + 1, 0, i);
pos = (pos + 1) % buffer.length;
}
return buffer[(buffer.indexOf(iterations) + 1) % buffer.length];
}
Insert cell
function part1(input) {
return spinlock(input, 2017);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function spinlockZero(steps, iterations) {
let [pos, valueAfterZero] = [0, null];
for (let i = 1; i <= iterations; i++) {
pos = (pos + steps) % i;
if (pos === 0) {
valueAfterZero = i;
}
pos = (pos + 1) % (i + 1);
}
return valueAfterZero;
}
Insert cell
function part2(input) {
return spinlockZero(puzzleInput, 50000000);
}
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