From b63e5b478bc562099ffe4216a7ed4244bb7facf9 Mon Sep 17 00:00:00 2001 From: Keenan Tims Date: Fri, 4 Dec 2026 17:42:41 -0700 Subject: [PATCH] 2026/day4: slight simplification / optimization --- 2026/src/day4.rs | 14 +++++--------- README.md | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) 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