Implement 2023 day 16 part 1

This commit is contained in:
2023-12-16 11:38:50 +01:00
parent 682e6f06b8
commit c2389e93af
4 changed files with 135 additions and 2 deletions

View File

@@ -289,6 +289,21 @@ impl<T: AsRef<[u8]>> Grid<T> {
}
}
impl Grid<Vec<u8>> {
pub fn zeroed(width: usize, height: usize) -> Self {
let mut data = vec![0; (width + 1) * height];
for line_end in data[width..].iter_mut().step_by(width + 1) {
*line_end = b'\n';
}
Self {
width: width + 1,
data,
}
}
}
impl<T: AsMut<[u8]> + AsRef<[u8]>> Grid<T> {
pub fn rows_mut(&mut self) -> impl Iterator<Item = &mut [u8]> {
let width = self.width();