day15: cleanup, clippies
Some checks failed
test / AoC 2024 (push) Has been cancelled

This commit is contained in:
Keenan Tims 2024-12-15 01:03:02 -08:00
parent 411d6aa26d
commit c261ee56fe
Signed by: ktims
GPG Key ID: 11230674D69038D4

View File

@ -18,12 +18,7 @@ impl Warehouse {
fn step_robot(&mut self, dir: Move) { fn step_robot(&mut self, dir: Move) {
let start = self.robot_pos.clone(); let start = self.robot_pos.clone();
if self.push(&start, &dir) { if self.push(&start, &dir) {
self.robot_pos = match dir { self.robot_pos = &self.robot_pos + dir.ofs();
Move::Left => (self.robot_pos.x() - 1, self.robot_pos.y()).to_coord(),
Move::Right => (self.robot_pos.x() + 1, self.robot_pos.y()).to_coord(),
Move::Up => (self.robot_pos.x(), self.robot_pos.y() - 1).to_coord(),
Move::Down => (self.robot_pos.x(), self.robot_pos.y() + 1).to_coord(),
}
} }
} }
@ -61,7 +56,7 @@ impl Warehouse {
fn can_push(&mut self, pos: &Coord2d, dir: &Move) -> bool { fn can_push(&mut self, pos: &Coord2d, dir: &Move) -> bool {
let target = pos + dir.ofs(); let target = pos + dir.ofs();
return match self.map.get(&target).unwrap() { match self.map.get(&target).unwrap() {
b'#' => false, b'#' => false,
b'.' => true, b'.' => true,
b'O' => self.can_push(&target, dir), b'O' => self.can_push(&target, dir),
@ -69,7 +64,7 @@ impl Warehouse {
b']' => self.can_push(&target, dir) && self.can_push(&(&target + (-1, 0)), dir), b']' => self.can_push(&target, dir) && self.can_push(&(&target + (-1, 0)), dir),
b'[' => self.can_push(&target, dir) && self.can_push(&(&target + (1, 0)), dir), b'[' => self.can_push(&target, dir) && self.can_push(&(&target + (1, 0)), dir),
c => panic!("unexpected char {}", c), c => panic!("unexpected char {}", c),
}; }
} }
fn embiggen(&mut self) { fn embiggen(&mut self) {