Skip to content

Instantly share code, notes, and snippets.

@neofight78
Created December 1, 2021 20:19
Show Gist options
  • Save neofight78/227baf6dfe2f053e974add7e71723853 to your computer and use it in GitHub Desktop.
Save neofight78/227baf6dfe2f053e974add7e71723853 to your computer and use it in GitHub Desktop.
Advent of Code 2021 - Day 1: Sonar Sweep
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