From ceffe97bf24dd98803796240dd2f4dfd7ba62280 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Wed, 25 Dec 2024 11:26:48 -0800 Subject: [PATCH] checkpoint --- day06/src/main.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/day06/src/main.rs b/day06/src/main.rs index e25a8e9..f338396 100644 --- a/day06/src/main.rs +++ b/day06/src/main.rs @@ -117,7 +117,7 @@ impl Board { parse(input).unwrap() } - fn step(&mut self) -> Option { + 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)); + } }