diff options
-rw-r--r-- | 2021/day9/src/main.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/2021/day9/src/main.rs b/2021/day9/src/main.rs index 5d84be9..524fb1b 100644 --- a/2021/day9/src/main.rs +++ b/2021/day9/src/main.rs | |||
@@ -43,14 +43,19 @@ fn main() { | |||
43 | .get(ndx) | 43 | .get(ndx) |
44 | .unwrap_or(&9); | 44 | .unwrap_or(&9); |
45 | 45 | ||
46 | let down = match points.get(idx + 1) { | 46 | let down = points |
47 | Some(line) => line.get(ndx).unwrap_or(&9), | 47 | .get(idx + 1) |
48 | None => &9, | 48 | .unwrap_or_else(|| &nine) |
49 | }; | 49 | .get(ndx) |
50 | .unwrap_or_else(|| &9); | ||
50 | 51 | ||
51 | let left = height.get((ndx as isize - 1) as usize).unwrap_or(&9); | 52 | let left = height |
53 | .get((ndx as isize - 1) as usize) | ||
54 | .unwrap_or_else(|| &9); | ||
52 | 55 | ||
53 | let right = height.get(ndx + 1).unwrap_or(&9); | 56 | let right = height |
57 | .get((ndx as isize + 1) as usize) | ||
58 | .unwrap_or_else(|| &9); | ||
54 | 59 | ||
55 | if num < up && num < down && num < right && num < left { | 60 | if num < up && num < down && num < right && num < left { |
56 | risk_level += 1 + *num; | 61 | risk_level += 1 + *num; |