//! Day 01 of 2021. use crate::prelude::*; /// Get the solution for day 01 of 2021. pub fn solution() -> Solution { Solution::new(Day::new(1, 2021), part_1, part_2).with_expected(1451, 1395) } /// The logic to solve part one. fn part_1(input: &str) -> Result { Ok( parse_measurements(input)? .into_iter() .tuple_windows() .filter(|(previous, next)| next > previous) .count() .to_string(), ) } /// The logic to solve part two. fn part_2(input: &str) -> Result { Ok( parse_measurements(input)? .into_iter() .tuple_windows() .filter(|(a, b, c, d)| b + c + d > a + b + c) .count() .to_string(), ) } /// Parse the measurements from the puzzle input. fn parse_measurements(input: &str) -> Result> { input .lines() .map(|line| line.parse::()) .collect::>() .map_err(Into::into) }