···576576 .find_map(|(p, t)| if t == tile { Some(p) } else { None })
577577 }
578578579579- pub fn cursor_at<D: Movement>(&self, tile: &T, dir: D) -> Option<GridCursor<T, D>> {
579579+ pub fn cursor_at_tile<D: Movement>(&self, tile: &T, dir: D) -> Option<GridCursor<T, D>> {
580580 self.find_tile(tile).map(|pos| self.cursor(pos, dir))
581581 }
582582}
···831831 /// Create a new cursor at the given position and direction.
832832 pub fn new(grid: &'a Grid<T>, pos: Position, dir: D) -> Self {
833833 Self { grid, pos, dir }
834834+ }
835835+836836+ /// Get the current state of the cursor (position and direction) for use in tracking
837837+ pub fn state(&self) -> (Position, D) {
838838+ (self.pos, self.dir)
834839 }
835840836841 /// Move the cursor forward one step in the direction it is facing.
+4-4
years/2024/src/day_6.rs
···2424 let mut visited = HashSet::new();
25252626 while let Some((pos, tile)) = curs.peek_forward() {
2727- visited.insert((curs.pos, curs.dir));
2727+ visited.insert(curs.state());
2828 if tile.is_open() && pos != obs_pos {
2929 curs.move_forward();
3030 } else {
3131 curs.turn(true);
3232 }
33333434- if visited.contains(&(curs.pos, curs.dir)) {
3434+ if visited.contains(&curs.state()) {
3535 return true;
3636 }
3737 }
···44444545 fn part_1(input: Self::Input) -> Option<String> {
4646 let mut curs = input
4747- .cursor_at(&Tile::GuardStart, Direction::North)
4747+ .cursor_at_tile(&Tile::GuardStart, Direction::North)
4848 .unwrap();
49495050 let mut visited = HashSet::with_capacity(input.width() * input.height());
···66666767 fn part_2(input: Self::Input) -> Option<String> {
6868 let mut curs = input
6969- .cursor_at(&Tile::GuardStart, Direction::North)
6969+ .cursor_at_tile(&Tile::GuardStart, Direction::North)
7070 .unwrap();
71717272 let start_curs = curs;