From 83e957d5f94c540f36b9a6b200d17ef629dd1c57 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Fri, 19 Dec 2025 15:14:39 +0000 Subject: [PATCH] Fix day 3 error case This doesn't actually matter for the input data given, but it ensures we get the right error when the battery list is too short, instead of unwrapping. --- rust/puzzles/day3.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rust/puzzles/day3.rs b/rust/puzzles/day3.rs index 1e05ff0..fda7e32 100644 --- a/rust/puzzles/day3.rs +++ b/rust/puzzles/day3.rs @@ -52,6 +52,9 @@ fn max_batteries(n: usize, v: &[u8]) -> Option> { let mut remaining = n; let mut slice = v; while remaining > 0 { + if slice.len() - remaining + 1 == 0 { + return None; + } let (b, i) = find_max(&slice[..slice.len() - remaining + 1]); result.push(b); remaining -= 1;