From 2e000f683f4553049a26c47b837fa4cb67a9cbf0 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Tue, 10 Oct 2023 16:53:26 +0200 Subject: [PATCH] First half of Day 1 Finished. --- day1/src/elves.rs | 6 ++---- day1/src/main.rs | 7 +++++-- 2 files changed, 7 insertions(+), 6 deletions(-) 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()); }