aoc/year2025/
day01.rs

1//! # Secret Entrance
2//!
3//! Part two left turns are easier if we first "reverse" the dial, then treat it as a right turn.
4use crate::util::parse::*;
5
6type Input = (i32, i32);
7
8pub fn parse(input: &str) -> Input {
9    let directions = input.bytes().filter(|&b| b.is_ascii_uppercase());
10    let amounts = input.iter_signed::<i32>();
11
12    let mut dial = 50;
13    let mut part_one = 0;
14    let mut part_two = 0;
15
16    for (direction, amount) in directions.zip(amounts) {
17        if direction == b'R' {
18            part_two += (dial + amount) / 100;
19            dial = (dial + amount) % 100;
20        } else {
21            let reversed = (100 - dial) % 100;
22            part_two += (reversed + amount) / 100;
23            dial = (dial - amount).rem_euclid(100);
24        }
25        part_one += i32::from(dial == 0);
26    }
27
28    (part_one, part_two)
29}
30
31pub fn part1(input: &Input) -> i32 {
32    input.0
33}
34
35pub fn part2(input: &Input) -> i32 {
36    input.1
37}