diff --git a/.aoc_tiles/tiles/2025/04.png b/.aoc_tiles/tiles/2025/04.png
index 2b574ec..4a614fa 100644
Binary files a/.aoc_tiles/tiles/2025/04.png and b/.aoc_tiles/tiles/2025/04.png differ
diff --git a/README.md b/README.md
index 2518675..effef6d 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
- 2025 - 7 ⭐ - Rust
+ 2025 - 8 ⭐ - Rust
diff --git a/utils/grid/lib.rs b/utils/grid/lib.rs
index 2b0b6e3..38d395a 100644
--- a/utils/grid/lib.rs
+++ b/utils/grid/lib.rs
@@ -149,7 +149,34 @@ impl<'a, T: Clone + Eq + PartialEq + Debug> Iterator for CoordIter<'a, T> {
type Item = Coord2d;
fn next(&mut self) -> Option {
if self.pos < self.grid.data.len() {
- self.grid.coord(self.pos as i64).into()
+ self.pos += 1;
+ self.grid.coord(self.pos as i64 - 1).into()
+ } else {
+ None
+ }
+ }
+}
+
+#[derive(Debug)]
+pub struct ItemIter<'a, T> {
+ pos: usize,
+ grid: &'a Grid,
+}
+
+pub struct Item<'a, T> {
+ pub pos: Coord2d,
+ pub value: &'a T,
+}
+
+impl<'a, T: Clone + Eq + PartialEq + Debug> Iterator for ItemIter<'a, T> {
+ type Item = Item<'a, T>;
+ fn next(&mut self) -> Option {
+ if self.pos < self.grid.data.len() {
+ self.pos += 1;
+ Some(Item {
+ pos: self.grid.coord(self.pos as i64 - 1).unwrap(),
+ value: &self.grid.data[self.pos - 1],
+ })
} else {
None
}
@@ -226,9 +253,12 @@ impl Grid {
})
}
}
- // pub fn coord_iter(&self) -> CoordIter<_> {
- // CoordIter { pos: 0, grid: self }
- // }
+ pub fn coord_iter<'a>(&'a self) -> CoordIter<'a, T> {
+ CoordIter { pos: 0, grid: self }
+ }
+ pub fn item_iter<'a>(&'a self) -> ItemIter<'a, T> {
+ ItemIter { pos: 0, grid: self }
+ }
pub fn is_valid(&self, c: &C) -> bool {
if c.x() < 0 || c.x() >= self.width {
return false;
@@ -292,7 +322,7 @@ impl Grid {
}
}
- pub fn row_iter(&self, y: i64) -> Option> {
+ pub fn row_iter<'a>(&'a self, y: i64) -> Option> {
if (y as usize) < self.height() {
Some(GridRowIter::new(self, y))
} else {
@@ -308,7 +338,7 @@ impl Grid {
}
}
- pub fn col_iter(&self, x: i64) -> Option> {
+ pub fn col_iter<'a>(&'a self, x: i64) -> Option> {
if (x as usize) < self.width() {
Some(GridColIter::new(self, x))
} else {
@@ -316,13 +346,13 @@ impl Grid {
}
}
- pub fn find(&self, haystack: &T) -> Option {
+ pub fn find(&self, needle: &T) -> Option {
self.coord(
self.data
.iter()
.enumerate()
.find_map(|(pos, val)| {
- if val == haystack {
+ if val == needle {
Some(pos as i64)
} else {
None