AoC - Day 1a
December 4, 2025 •2 min read
Secret Entrance
Part 1
You arrive at the secret entrance to the North Pole base ready to start decorating. Unfortunately, the password seems to have been changed, so you can't get in. A document taped to the wall helpfully explains:
"Due to new security protocols, the password is locked in the safe below. Please see the attached document for the new combination."
The safe has a dial with only an arrow on it; around the dial are the numbers 0 through 99 in order. As you turn the dial, it makes a small click noise as it reaches each number.
The attached document (your puzzle input) contains a sequence of rotations, one per line, which tell you how to open the safe. A rotation starts with an L or R which indicates whether the rotation should be to the left (toward lower numbers) or to the right (toward higher numbers). Then, the rotation has a distance value which indicates how many clicks the dial should be rotated in that direction.
So, if the dial were pointing at 11, a rotation of R8 would cause the dial to point at 19. After that, a rotation of L19 would cause it to point at 0.
Because the dial is a circle, turning the dial left from 0 one click makes it point at 99. Similarly, turning the dial right from 99 one click makes it point at 0.
So, if the dial were pointing at 5, a rotation of L10 would cause it to point at 95. After that, a rotation of R5 could cause it to point at 0.
The dial starts by pointing at 50.
Solution
const fileContent = require("fs").readFileSync(
require("path").join(process.cwd(), "day1.txt"),
"utf8"
);
const lines = fileContent.split("\n");
let count = 0;
const DIAL_LENGTH = 100;
lines.reduce((counter, line) => {
const direction = line.at(0);
const steps = parseInt(line.slice(1));
if (direction === "R") {
const result = (counter + steps) % DIAL_LENGTH;
result === 0 ? count++ : null;
return result;
} else {
const result =
(((counter - steps) % DIAL_LENGTH) + DIAL_LENGTH) % DIAL_LENGTH;
result === 0 ? count++ : null;
return result;
}
}, 50);