Function advent_of_code_2021::day_1::sum_windows[−][src]

fn sum_windows(depths: &Vec<i32>) -> Vec<i32>ⓘ
Notable traits for Vec<u8, A>
impl<A> Write for Vec<u8, A> where
    A: Allocator, 
Expand description

Iterate over a moving window of three consecutive items, returning a vector where each item is the sum of te current window.

Example from puzzle specification

assert_eq!(
  sum_windows(&input),
  vec!(
    607, // 199 + 200 + 208
    618, // 200 + 208 + 210
    618, // 208 + 210 + 200
    617, // 210 + 200 + 207
    647, // 200 + 207 + 240
    716, // 207 + 240 + 269
    769, // 240 + 269 + 260
    792  // 269 + 260 + 263
  )
);