checkpoint

This commit is contained in:
Joe Ardent 2024-12-25 11:26:48 -08:00
parent b79d418d4e
commit ceffe97bf2

View file

@ -117,7 +117,7 @@ impl Board {
parse(input).unwrap() parse(input).unwrap()
} }
fn step(&mut self) -> Option<Loc> { fn step(&mut self) -> Option<(Loc, Dir)> {
let (loc, dir) = &mut self.guard; let (loc, dir) = &mut self.guard;
*self *self
.cells .cells
@ -133,12 +133,12 @@ impl Board {
match next_cell { match next_cell {
Cell::Obstacle => { Cell::Obstacle => {
*dir = dir.rot(); *dir = dir.rot();
Some(*loc) Some((*loc, *dir))
} }
Cell::Empty | Cell::Visited => { Cell::Empty | Cell::Visited => {
*next_cell = Cell::Guard(*dir); *next_cell = Cell::Guard(*dir);
*loc = nloc; *loc = nloc;
Some(nloc) Some((nloc, *dir))
} }
_ => unreachable!(), _ => unreachable!(),
} }
@ -150,7 +150,7 @@ impl Board {
fn run(&mut self) -> usize { fn run(&mut self) -> usize {
let mut locs = HashSet::new(); let mut locs = HashSet::new();
locs.insert(self.guard.0); locs.insert(self.guard.0);
while let Some(loc) = self.step() { while let Some(loc) = self.step().map(|l| l.0) {
locs.insert(loc); locs.insert(loc);
} }
locs.len() locs.len()
@ -234,5 +234,7 @@ mod test {
} }
#[test] #[test]
fn p2() {} fn p2() {
assert_eq!(6, pt2(INPUT));
}
} }