use crate::prelude::*; pub fn solution() -> Solution { Solution::new(Day::new(1, 2021), part_1, part_2).with_expected(1451, 1395) } fn part_1(input: &str) -> Result { Ok( parse_measurements(input)? .into_iter() .tuple_windows() .filter(|(previous, next)| next > previous) .count() .to_string(), ) } 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(), ) } fn parse_measurements(input: &str) -> Result> { input .lines() .map(|line| line.parse::()) .collect::>() .map_err(Into::into) }