From aaa54e057c1e0716bfcec9fa12617636d57de668 Mon Sep 17 00:00:00 2001 From: Maurice Wangleng Tan Date: Mon, 2 Dec 2024 20:57:13 +0800 Subject: [PATCH] Day 02: Nit code improvement --- src/bin/day02/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bin/day02/main.rs b/src/bin/day02/main.rs index 4c0ddf1..297ca18 100644 --- a/src/bin/day02/main.rs +++ b/src/bin/day02/main.rs @@ -16,14 +16,16 @@ fn is_safe_increasing(values: &[i32]) -> bool { values .iter() .zip(values.iter().skip(1)) - .all(|(a, b)| b - a >= 1 && b - a <= 3) + .map(|(a, b)| b - a) + .all(|diff| diff >= 1 && diff <= 3) } fn is_safe_decreasing(values: &[i32]) -> bool { values .iter() .zip(values.iter().skip(1)) - .all(|(a, b)| a - b >= 1 && a - b <= 3) + .map(|(a, b)| a - b) + .all(|diff| diff >= 1 && diff <= 3) } fn p1(input: &str) -> String {