Module advent_of_code_2021::day_1[−][src]

Expand description

This is my solution for Advent of Code - Day 1 - Sonar Sweep

The challenge today was to analyse a sequence of integer depths and determine a measure of how often these were increasing.

For part one, the challenge was to count the number of values that were greater than the previous value in the list. count_increments has been written to do that by chaining built-in methods on Rust’s iterators.

Part two expands on that, requiring the same count be run on the sums of a moving window of three consecutive values over the input. sum_windows provides a vector of these sums, which is suitable to then be passed to count_increments to produce the final answer. For this I originally included itertools to use their izip! macro to zip three iterators together, each offset by one more. I updated it to use slice::windows thanks to @bjgill’s comment on the x-gov slack channel.

Functions

Iterate over a moving window of pairs, returning the count where the second number is greater that the first.

This is the entry point for the day’s puzzle solutions. It will load the input file, parse it into a Vec<i32> and pass it to the relevant functions for each part.

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