use std::fs::File; use std::io::BufRead; use std::io::BufReader; use clap::Arg; use clap::Command; fn main() { let matches = Command::new("Day1").arg(Arg::new("filename")).get_matches(); let filename = matches .get_one::("filename") .expect("Need a filename"); println!("Processing {}...", filename); let file = File::open(filename).expect("Can't read file"); let reader = BufReader::new(file); let mut max_calories = 0; let mut elf_calories = 0; for line in reader.lines() { let line = line.unwrap(); let line = line.trim(); // XXX I want to do this with an iterator! if line.is_empty() { if elf_calories > max_calories { max_calories = elf_calories; } elf_calories = 0; } else { println!("Line: {}", line); elf_calories += line.parse::().unwrap(); } } println!("Max: {}", max_calories); }