Exercise 46

This commit is contained in:
akshitgautam42 2023-11-14 23:23:52 +05:30
parent 007f5672c7
commit 569db57eff

View File

@ -14,7 +14,7 @@
// Execute `rustlings hint hashmaps2` or use the `hint` watch subcommand for a // Execute `rustlings hint hashmaps2` or use the `hint` watch subcommand for a
// hint. // hint.
// I AM NOT DONE
use std::collections::HashMap; use std::collections::HashMap;
@ -36,10 +36,20 @@ fn fruit_basket(basket: &mut HashMap<Fruit, u32>) {
Fruit::Pineapple, Fruit::Pineapple,
]; ];
for fruit in fruit_kinds { for fruit in fruit_kinds {
// TODO: Insert new fruits if they are not already present in the // TODO: Insert new fruits if they are not already present in the
// basket. Note that you are not allowed to put any type of fruit that's // basket. Note that you are not allowed to put any type of fruit that's
// already present! // already present!
if !basket.contains_key(&fruit){
basket.insert(fruit,1);
}
}
let total_count:u32 = basket.values().sum();
if total_count <=11{
*basket.entry(Fruit::Pineapple).or_insert(0)+=12-total_count;
} }
} }