diff --git a/day1/src/elves.rs b/day1/src/elves.rs index 46b28e9..d3ddf38 100644 --- a/day1/src/elves.rs +++ b/day1/src/elves.rs @@ -9,10 +9,8 @@ impl Elf { } } - pub fn print_inventory(& self) + pub fn get_total(& self) -> u64 { - for inv in &self.inventory { - println!("{}",inv) - } + self.inventory.iter().sum() } } \ No newline at end of file diff --git a/day1/src/main.rs b/day1/src/main.rs index 7fe9bd0..c4d0dc7 100644 --- a/day1/src/main.rs +++ b/day1/src/main.rs @@ -45,8 +45,11 @@ fn main() } } + // Gathering all the total kcal onto a vector + let mut vec_total: Vec = Vec::new(); for elf in &vec_elf { - println!("Elf: "); - elf.print_inventory(); + vec_total.push(elf.get_total()); } + // Printing the max + println!("Most Calories: {}", vec_total.iter().max().unwrap()); }