From 838e77e03bea487d64aeee345f8c294fe392c389 Mon Sep 17 00:00:00 2001 From: Jonas Berlin Date: Sat, 5 Sep 2020 21:11:13 +0300 Subject: Cleanup --- challenge-076/xkr47/rust/ch-2.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-076/xkr47/rust/ch-2.rs b/challenge-076/xkr47/rust/ch-2.rs index ab6f8b75ae..4e21cdd096 100644 --- a/challenge-076/xkr47/rust/ch-2.rs +++ b/challenge-076/xkr47/rust/ch-2.rs @@ -61,7 +61,7 @@ impl SearchGrid { let left_coords = (0..self.height).map(|y| (0isize, y)).collect::>(); let top_coords = (0..self.width).map(|x| (x, 0isize)).collect::>(); - let bottom_coords = (0..self.width).map(|x| (x, self.height - 1)).collect::>(); + let bottom_coords = (0..self.width).map(|x| (x, self.height - 1)).collect::>(); let mut strings = left_coords.iter().skip(1).map(|coord| self.string_from(coord, (1, -1))).collect::>(); strings.extend(left_coords.iter().map(|coord| self.string_from(coord, (1, 0)))); -- cgit From b6986a601900f8bcf81add843cf89779afe7c1f5 Mon Sep 17 00:00:00 2001 From: Jonas Berlin Date: Sat, 5 Sep 2020 21:11:36 +0300 Subject: Bugfix - did not traverse full grid if width != height --- challenge-076/xkr47/rust/ch-2.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/challenge-076/xkr47/rust/ch-2.rs b/challenge-076/xkr47/rust/ch-2.rs index 4e21cdd096..d052e9bbb3 100644 --- a/challenge-076/xkr47/rust/ch-2.rs +++ b/challenge-076/xkr47/rust/ch-2.rs @@ -78,8 +78,9 @@ impl SearchGrid { } fn string_from(&self, (xstart, ystart): &(isize, isize), (xinc, yinc): (isize, isize)) -> String { - let x_coords = (0..self.width).map(|pos| xstart + (xinc * pos)); - let y_coords = (0..self.height).map(|pos| ystart + (yinc * pos)); + let max_extent = self.width.max(self.height); + let x_coords = (0..max_extent).map(|pos| xstart + (xinc * pos)); + let y_coords = (0..max_extent).map(|pos| ystart + (yinc * pos)); x_coords.zip(y_coords) .filter(|(x,y)| *x >= 0 && *y >= 0 && *x < self.width && *y < self.height) .map(|(x,y)| self.grid[y as usize][x as usize]) -- cgit