My submissions for Advent of Code 2025
adventofcode.com/2025
rust
aoc
1use std::fs::read_to_string;
2
3fn main() {
4 let (password, _) = read_to_string("../input.txt")
5 .expect("failed to open input file")
6 .lines()
7 .fold((0u32, 50), |(zero_count, position), rotation| {
8 let (direction, distance) = rotation.split_at(1);
9 let distance = distance.parse::<u16>().expect("failed to parse distance");
10 let modulo_distance = distance % 100;
11 let (new_position, overflow) = match direction {
12 "L" => {
13 if modulo_distance > position {
14 (100 - (modulo_distance - position), position != 0)
15 } else {
16 (position - modulo_distance, position == modulo_distance)
17 }
18 }
19 "R" => {
20 let turned = position + modulo_distance;
21 (turned % 100, turned >= 100)
22 }
23 other => panic!("unexpected direction {other}"),
24 };
25 let new_count = zero_count + (u32::from(distance) / 100) + if overflow { 1 } else { 0 };
26 (new_count, new_position)
27 });
28 println!("The door password is {password}!");
29}