Created
December 1, 2021 20:19
-
-
Save neofight78/227baf6dfe2f053e974add7e71723853 to your computer and use it in GitHub Desktop.
Advent of Code 2021 - Day 1: Sonar Sweep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn count_increments(measurements: &[u64]) -> usize { | |
measurements.windows(2).filter(|&w| w[1] > w[0]).count() | |
} | |
fn count_three_measurement_increments(measurements: &[u64]) -> usize { | |
count_increments( | |
&measurements | |
.windows(3) | |
.map(|w| w.iter().sum()) | |
.collect::<Vec<u64>>(), | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment