[go: nahoru, domu]

Skip to content

Commit

Permalink
Fixed warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-harding committed Sep 6, 2023
1 parent 17d7d16 commit 9be3fef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct Floor {
}

impl Floor {
#[allow(unused)]
pub fn new(width: usize, height: usize) -> Self {
Self {
width,
Expand All @@ -55,13 +56,15 @@ impl Floor {
(self.cells[bit / 8] >> (bit % 8)) & 1 == 1
}

#[allow(unused)]
pub fn set_off_limits(&mut self, x: usize, y: usize) {
assert!(x < self.width);
assert!(y < self.height);
let bit = y * self.width + x;
self.cells[bit / 8] |= 1 << (bit % 8);
}

#[allow(unused)]
pub fn is_valid_path(&self, steps: &[Step]) -> bool {
let mut x = 0;
let mut y = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct Solution;

impl RobotOnAGrid for Solution {
fn robot_on_a_grid(floor: &Floor) -> Option<Vec<Step>> {
let index = |x, y| y * floor.width() + x;
let mut access = vec![None; floor.width() * floor.height()];
for y in 1..floor.height() {
if floor.is_off_limits(0, y) {
Expand All @@ -25,14 +26,14 @@ impl RobotOnAGrid for Solution {
for x in 1..floor.width() {
let step = if floor.is_off_limits(x, y) {
continue;
} else if access[(y - 1) * floor.width() + x].is_some() {
} else if access[index(x, y - 1)].is_some() {
Step::Down
} else if access[y * floor.width() + x - 1].is_some() {
} else if access[index(x - 1, y)].is_some() {
Step::Right
} else {
continue;
};
access[y * floor.width() + x] = Some(step);
access[index(x, y)] = Some(step);
}
}

Expand All @@ -47,7 +48,7 @@ impl RobotOnAGrid for Solution {
let mut y = floor.height() - 1;
while i > 0 {
i -= 1;
let step = access[y * floor.width() + x].unwrap();
let step = access[index(x, y)].unwrap();
match step {
Step::Right => x -= 1,
Step::Down => y -= 1,
Expand Down

0 comments on commit 9be3fef

Please sign in to comment.