2021: day06: use a VecDeque for faster rotating

This commit is contained in:
Antoine Martin 2021-12-06 12:15:25 +01:00
parent fceda8ac1b
commit 7077559b3a

View file

@ -1,3 +1,4 @@
use std::collections::VecDeque;
use std::fmt::Write;
use std::str;
@ -31,7 +32,7 @@ fn part2(input: &str) -> Result<usize> {
}
struct School {
fish_timers: [usize; SPAWNING_DELAY as usize + 2],
fish_timers: VecDeque<usize>,
}
impl School {
@ -66,7 +67,9 @@ impl std::str::FromStr for School {
fish_timers[fish?] += 1;
}
Ok(School { fish_timers })
Ok(School {
fish_timers: fish_timers.into(),
})
}
}