From f5082b84418123fe1fa3a22805bab9488bb8ee24 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Wed, 1 Dec 2021 12:39:52 -0700 Subject: [PATCH] refactor day1 solution --- src/main.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 078a110..a22c59a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,13 +13,7 @@ fn read_file(filename: &str) -> Result { } fn count_incrementing_windows(window: usize, v: &[i64]) -> usize { - // create an array of the window sums and then window(2) that array to count increments - v.windows(window) - .map(|w| w.iter().sum()) - .collect::>() - .windows(2) - .filter(|s| s[1] > s[0]) - .count() + v[window..].iter().zip(v).filter(|(b, a)| b > a).count() } fn day01() -> Result<(usize, usize)> {