diff options
| author | Jonas Berlin <xkr47@outerspace.dyndns.org> | 2020-09-05 21:11:36 +0300 |
|---|---|---|
| committer | Jonas Berlin <xkr47@outerspace.dyndns.org> | 2020-09-05 21:11:36 +0300 |
| commit | b6986a601900f8bcf81add843cf89779afe7c1f5 (patch) | |
| tree | 3acef347d2ddab87b89c5bfe5298d27bc8cc53d7 | |
| parent | 838e77e03bea487d64aeee345f8c294fe392c389 (diff) | |
| download | perlweeklychallenge-club-b6986a601900f8bcf81add843cf89779afe7c1f5.tar.gz perlweeklychallenge-club-b6986a601900f8bcf81add843cf89779afe7c1f5.tar.bz2 perlweeklychallenge-club-b6986a601900f8bcf81add843cf89779afe7c1f5.zip | |
Bugfix - did not traverse full grid if width != height
| -rw-r--r-- | challenge-076/xkr47/rust/ch-2.rs | 5 |
1 files 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]) |
