mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-07 11:19:18 +00:00
Exercise 46
This commit is contained in:
parent
007f5672c7
commit
569db57eff
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user