diff --git a/2026/src/day4.rs b/2026/src/day4.rs index 724213a..b83d1cf 100644 --- a/2026/src/day4.rs +++ b/2026/src/day4.rs @@ -46,21 +46,17 @@ fn shortest_sequence(barcode: &[u8]) -> Vec { } fn shortest_sequence_len(barcode: &[u8]) -> u64 { - #[derive(Copy, Clone, PartialEq)] - enum Instruction { - Any, - Colour(u8), - } // Start with the shortest sequence, build it from the barcode, placing fixed barcodes for unknown instructions, skipping // when there is no constraint, and moving on to the next length if there is a clash + 'outer: for len in 1..=barcode.len() { - let mut instructions = Vec::from_iter(std::iter::repeat_n(Instruction::Any, len)); + let mut instructions = barcode[..len].to_vec(); for (i, c) in barcode.iter().enumerate() { if *c == b'?' { continue; - } else if instructions[i % len] == Instruction::Any { - instructions[i % len] = Instruction::Colour(*c) - } else if Instruction::Colour(*c) == instructions[i % len] { + } else if instructions[i % len] == b'?' { + instructions[i % len] = *c + } else if *c == instructions[i % len] { continue; } else { //clash so move on to the next length diff --git a/README.md b/README.md index ecd297f..2e75b02 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

- Advent of Code - 148/558 ⭐ + Advent of Code - 148/560 ⭐

2026 - 8 ⭐ - Rust