2021: day06: use a VecDeque for faster rotating
This commit is contained in:
parent
fceda8ac1b
commit
7077559b3a
|
@ -1,3 +1,4 @@
|
||||||
|
use std::collections::VecDeque;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
|
@ -31,7 +32,7 @@ fn part2(input: &str) -> Result<usize> {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct School {
|
struct School {
|
||||||
fish_timers: [usize; SPAWNING_DELAY as usize + 2],
|
fish_timers: VecDeque<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl School {
|
impl School {
|
||||||
|
@ -66,7 +67,9 @@ impl std::str::FromStr for School {
|
||||||
fish_timers[fish?] += 1;
|
fish_timers[fish?] += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(School { fish_timers })
|
Ok(School {
|
||||||
|
fish_timers: fish_timers.into(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue