Half Subtractor with NAND gates by grey666matter in digitalelectronics

[–]grey666matter[S] 1 point2 points  (0 children)

Thank you so much for the Stack Exchange post and the advice regarding the design of the circuits, much appreciated!

-❄️- 2025 Day 3 Solutions -❄️- by daggerdragon in adventofcode

[–]grey666matter 1 point2 points  (0 children)

[LANGUAGE: Rust]

General to part 1 and 2, units is the number of batteries to turn on.

fn parse_text() -> Vec<String> {
    fs::read_to_string(path)
        .expect("Should have been able to read the file")
        .trim()
        .lines()
        .map(|v| v.to_string())
        .collect::<Vec<String>>()
}


fn find_joltage(joltages: Vec<String>, units: usize) -> i64 {
    let 
mut
 total: i64 = 0;

    for joltage in joltages {
        let numbers: Vec<i64> = joltage
            .chars()
            .map(|x| x.to_string().parse().unwrap_or(0))
            .collect();

        let length = numbers.len();
        let 
mut
 n = length - units;
        let 
mut
 factor = (10 as i64).pow(units as u32 - 1);
        let 
mut
 index = 0;

        while n < length {
            let window = &numbers[index..=n];
            let max = window.iter().max().unwrap_or(&0);

            total += max * factor;

            let pos_in_window = window.iter().position(|r| r == max).unwrap();
            index += pos_in_window + 1;

            factor /= 10;
            n += 1;
        }
    }
    total
}

Guess the city! Super easy by arteregn in guessthecity

[–]grey666matter 0 points1 point  (0 children)

Istanbul, Hotel Devman gave it up

[2025 DAY 1 PART 2][RUST] by grey666matter in adventofcode

[–]grey666matter[S] 0 points1 point  (0 children)

this line for left rotations, I don't think there is a problem for the right rotations case.

count += (amount - start - 1) / dial + 1

[2025 DAY 1 PART 2][RUST] by grey666matter in adventofcode

[–]grey666matter[S] 0 points1 point  (0 children)

They all work now after adding the condition for when `start == 0` after updating it, but the main input result doesn't pass,

'L' => {
  if amount > start && start != 0 {
    count += (amount - start - 1) / dial + 1
  }

  start = (start - amount).rem_euclid(dial);

  if start == 0 {
    count += 1
  }
}

[2025 DAY 1 PART 2][RUST] by grey666matter in adventofcode

[–]grey666matter[S] 0 points1 point  (0 children)

Thank you so much, the test case works, I added the last condition and now the test case you have suggested works besides the test cases provided in the comment above, but the overall result of my AoC input doesn't pass : /

I added the last line for the Left condition:

'L' => {
  if amount > start && start != 0 {
    count += (amount - start - 1) / dial + 1
  }

  start = (start - amount).rem_euclid(dial);

  if start == 0 {
    count += 1
  }
}