Zero init > 1 init

This commit is contained in:
2023-12-15 09:03:06 +01:00
parent 6657519179
commit 673e8184ed

View File

@@ -73,15 +73,15 @@ pub fn part2(input: &[u8]) -> anyhow::Result<String> {
} }
} }
let mut box_slot = [1; 256]; let mut box_slot = [0; 256];
let mut total = 0; let mut total = 0;
for (&identifier, &focal_len) in &state { for (&identifier, &focal_len) in &state {
let index = hash(identifier); let index = hash(identifier);
let box_no = u32::from(index) + 1; let box_no = u32::from(index) + 1;
let slot_no = &mut box_slot[index as usize]; let slot_no = &mut box_slot[index as usize];
total += box_no * *slot_no * focal_len;
*slot_no += 1; *slot_no += 1;
total += box_no * *slot_no * focal_len;
} }
Ok(total.to_string()) Ok(total.to_string())