use color_eyre::eyre; use crate::lib::ParseLines; fn run(data: &str) -> eyre::Result<()> { let mut single_increases = 0; let mut window_increases = 0; let mut prev = (None, None, None); for res in data.parse_lines::() { let n = res?; if let Some(p) = prev.2 { // apparently we can't combine "if let" and regular boolean conditions if n > p { single_increases += 1; } } if let (Some(first), Some(second), Some(third)) = prev { if (n + second + third) > (first + second + third) { window_increases += 1; } } // would have forgotten this if not for the warning triggered by "let mut" without mutation prev = (prev.1, prev.2, Some(n)); } println!("One: {}", single_increases); println!("Two: {}", window_increases); Ok(()) }