mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Zero init > 1 init
This commit is contained in:
@@ -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;
|
||||
|
||||
for (&identifier, &focal_len) in &state {
|
||||
let index = hash(identifier);
|
||||
let box_no = u32::from(index) + 1;
|
||||
let slot_no = &mut box_slot[index as usize];
|
||||
total += box_no * *slot_no * focal_len;
|
||||
*slot_no += 1;
|
||||
total += box_no * *slot_no * focal_len;
|
||||
}
|
||||
|
||||
Ok(total.to_string())
|
||||
|
||||
Reference in New Issue
Block a user