use linebuffer::{ buf::forward, ParsedLines, }; use std::{ io, str, fs, }; #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Default, Copy)] struct MaybeU64(Option); impl str::FromStr for MaybeU64 { type Err = ::Err; #[inline] fn from_str(s: &str) -> Result { if s.is_empty() { Ok(Self(None)) } else { Ok(Self(Some(s.parse()?))) } } } fn input_reader(input: R) -> ParsedLines> { ParsedLines::new(input) } fn main() -> Result<(), Box> { let mut reader = input_reader(fs::OpenOptions::new().read(true).open("input")?); let mut last_elf = 0; let mut max_elf = 0; while let Some(res) = reader.try_next() { match res.expect("Failed to parse line").0 { Some(value) => last_elf += value, None if last_elf > max_elf => { max_elf = std::mem::replace(&mut last_elf, 0); }, _ => last_elf = 0, } } println!("{}", std::cmp::max(max_elf, last_elf)); Ok(()) }