aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-09-05 19:20:51 +0100
committerGitHub <noreply@github.com>2020-09-05 19:20:51 +0100
commit017aa8603a7c5047e1d9a1d0842c07aed55f7321 (patch)
treebbc823f3cbfe73bacb78e3b461050c9d4c494f4f
parent77b80f801f3a7b899759618b7c82fc251d465182 (diff)
parentb6986a601900f8bcf81add843cf89779afe7c1f5 (diff)
downloadperlweeklychallenge-club-017aa8603a7c5047e1d9a1d0842c07aed55f7321.tar.gz
perlweeklychallenge-club-017aa8603a7c5047e1d9a1d0842c07aed55f7321.tar.bz2
perlweeklychallenge-club-017aa8603a7c5047e1d9a1d0842c07aed55f7321.zip
Merge pull request #2211 from xkr47/pwc076-2
Pwc076 task 2 bugfix
-rw-r--r--challenge-076/xkr47/rust/ch-2.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/challenge-076/xkr47/rust/ch-2.rs b/challenge-076/xkr47/rust/ch-2.rs
index ab6f8b75ae..d052e9bbb3 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::<Vec<_>>();
let top_coords = (0..self.width).map(|x| (x, 0isize)).collect::<Vec<_>>();
- let bottom_coords = (0..self.width).map(|x| (x, self.height - 1)).collect::<Vec<(isize, isize)>>();
+ let bottom_coords = (0..self.width).map(|x| (x, self.height - 1)).collect::<Vec<_>>();
let mut strings = left_coords.iter().skip(1).map(|coord| self.string_from(coord, (1, -1))).collect::<Vec<String>>();
strings.extend(left_coords.iter().map(|coord| self.string_from(coord, (1, 0))));
@@ -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])