Implement 2023 day 10 part 1

This commit is contained in:
2023-12-10 10:38:16 +01:00
parent 126eeb7587
commit f1b23b0116
3 changed files with 106 additions and 4 deletions

View File

@@ -146,11 +146,9 @@ pub fn get_both<T>(slice: &mut [T], first: usize, second: usize) -> (&mut T, &mu
}
}
#[allow(unused)]
#[derive(Debug, Default)]
pub struct IndexSet(Vec<u32>);
#[allow(unused)]
impl IndexSet {
pub fn with_capacity(capacity: usize) -> Self {
Self(Vec::with_capacity(
@@ -278,6 +276,12 @@ impl<'a> Grid<'a> {
.chunks_exact(self.width)
.map(move |row| &row[..width])
}
pub fn find(&self, c: u8) -> Option<(usize, usize)> {
let pos = self.data.iter().position(|&d| d == c)?;
Some((pos % self.width, pos / self.width))
}
}
impl<'a> Index<usize> for Grid<'a> {