Day 1: Secret Entrance

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

you are viewing a single comment's thread
view the rest of the comments
[โ€“] 2 points 9 months ago

So, obviously the bot didnt work, thanks Ategon for covering :D

Here is the dumb solution for pt2, everyone can share in my shame:

#[test]
    fn test_2025_1_part2() {
        let input = std::fs::read_to_string("input/2025/day_1.txt").unwrap();
        let turns = input
            .lines()
            .map(|line| {
                let value = line[1..].parse::<i32>().unwrap();
                if line[0..1] == *"L" {
                    -value
                } else {
                    value
                }
            })
            .collect::<Vec<i32>>();
        let mut zero_ctr = 0;
        let mut pos = 50;
        for turn in turns {
            print!("{pos}->");

            let mut zero_passes = 0;
            if turn > 0 {
                for _ in 0..turn {
                    pos += 1;
                    if pos == 100 {
                        pos = 0;
                        zero_passes += 1;
                    }
                }
            } else {
                for _ in 0..-turn {
                    pos -= 1;
                    if pos == 0 {
                        zero_passes += 1;
                    }
                    if pos == -1 {
                        pos = 99;
                    }
                }
            };
            println!("{turn}->{pos}: {zero_passes}");
            zero_ctr += zero_passes;
        }
        println!("zero ctr: {}", zero_ctr);
    }
  • source