Metadata
-
Date
-
Tagged
-
Part of series
-
Older post
-
Newer post
Advent of Code 2025 Day 1
Day 1: Secret Entrance
https://adventofcode.com/2025/day/1
This year, you need to help decorate the North Pole. The elves left to deal with their latest emergency.
When you arrive at the gate to the North Pole, it’s locked. The lock is one of the rotary doo-dads. You know, the ones you see safe crackers put their ear against in the movies to listen for clicks.
You listen for clicks, but quickly remember you’re not a lawyer, so this might take a while.
The lock has the numbers 0 through 99 in clockwise order.
Todays input is a list of turn instructions that just so happens to be left near the lock. Neat! Convenient! Secure!
An example input looks like this:
L68L30R48L5R60L55L1L99R14L82Each line is an instruction.
L or R indicates the direction to turn.
Lfor left or counterclockwise.Rfor right or clockwise.
The number indicates how many steps you should turn in that direction.
The dial on the lock starts pointed at 50.
Part 1
The instuctions don’t really open the lock,
the amount of times the dial is left pointing at 0 after an instruction does.
fn part_1(input: &str) -> usize { let mut pos: i32 = 50; let mut sum = 0; for line in input.lines() { let dir = if line.starts_with('R') { 1 } else { -1 }; let num: i32 = line[1..].parse().unwrap(); pos = (pos + dir * num).rem_euclid(100); if pos == 0 { sum += 1 } } sum}Part 2
That wasn’t correct either.
The password is the amount of times the dial points at 0 at any time,
not just at the end of an instruction.
fn part_2(input: &str) -> usize { let mut pos: i32 = 50; let mut sum = 0; for line in input.lines() { let dir = if line.starts_with('R') { 1 } else { -1 }; let num: i32 = line[1..].parse().unwrap(); for _ in 0..num { pos = (pos + dir).rem_euclid(100); if pos == 0 { sum += 1 } } } sum}Final code
pub fn part_1(input: &str) -> usize { let mut pos: i32 = 50; let mut sum = 0; for line in input.lines() { let dir = if line.starts_with('R') { 1 } else { -1 }; let num: i32 = line[1..].parse().unwrap(); pos = (pos + dir * num).rem_euclid(100); if pos == 0 { sum += 1 } } sum}
pub fn part_2(input: &str) -> usize { let mut pos: i32 = 50; let mut sum = 0; for line in input.lines() { let dir = if line.starts_with('R') { 1 } else { -1 }; let num: i32 = line[1..].parse().unwrap(); for _ in 0..num { pos = (pos + dir).rem_euclid(100); if pos == 0 { sum += 1 } } } sum}