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.
This commit is contained in:
George Thomas 2025-12-19 15:14:39 +00:00
parent 2258f965c1
commit 83e957d5f9

View File

@ -52,6 +52,9 @@ fn max_batteries(n: usize, v: &[u8]) -> Option<Vec<u8>> {
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;