1
0
Fork 0

First half of Day 1 Finished.

This commit is contained in:
Yohan Boujon 2023-10-10 16:53:26 +02:00
parent 9d0fc7d649
commit 2e000f683f
2 changed files with 7 additions and 6 deletions

View file

@ -9,10 +9,8 @@ impl Elf {
} }
} }
pub fn print_inventory(& self) pub fn get_total(& self) -> u64
{ {
for inv in &self.inventory { self.inventory.iter().sum()
println!("{}",inv)
}
} }
} }

View file

@ -45,8 +45,11 @@ fn main()
} }
} }
// Gathering all the total kcal onto a vector
let mut vec_total: Vec<u64> = Vec::new();
for elf in &vec_elf { for elf in &vec_elf {
println!("Elf: "); vec_total.push(elf.get_total());
elf.print_inventory();
} }
// Printing the max
println!("Most Calories: {}", vec_total.iter().max().unwrap());
} }