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