checkpoint
This commit is contained in:
parent
b79d418d4e
commit
ceffe97bf2
1 changed files with 7 additions and 5 deletions
|
@ -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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue