use std::error::Error; use std::fs; fn main() -> Result<(), Box> { let file_str = fs::read_to_string("input.txt")?; let mut elves: Vec> = Vec::new(); let mut totals: Vec = Vec::new(); for raw_elf in file_str.split("\n\n") { let elf: Vec = raw_elf.split('\n') .filter(|value| value.len() > 0) .map(move |value| { value.parse::().unwrap() }) .collect(); let sum = elf .clone() .into_iter() .reduce(|accum, item| accum + item) .unwrap(); elves.push(elf); totals.push(sum); } let most = totals.iter().max().unwrap(); println!("{:?}{:?}", elves, totals); println!("Max calories: {}", most); Ok(()) }