From b5715d6b6e7d60e8b662ad4b46f0e1f1e7e445c1 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Tue, 14 Dec 2021 00:00:46 +0300 Subject: 2021, day9: fluff --- 2021/day9/src/main.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to '2021') 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() { .get(ndx) .unwrap_or(&9); - let down = match points.get(idx + 1) { - Some(line) => line.get(ndx).unwrap_or(&9), - None => &9, - }; + let down = points + .get(idx + 1) + .unwrap_or_else(|| &nine) + .get(ndx) + .unwrap_or_else(|| &9); - let left = height.get((ndx as isize - 1) as usize).unwrap_or(&9); + let left = height + .get((ndx as isize - 1) as usize) + .unwrap_or_else(|| &9); - let right = height.get(ndx + 1).unwrap_or(&9); + let right = height + .get((ndx as isize + 1) as usize) + .unwrap_or_else(|| &9); if num < up && num < down && num < right && num < left { risk_level += 1 + *num; -- cgit v1.2.3-70-g09d2