Lesson 17 of 34 · Arrays & Lists
Boss: The Grand Mimic's Treasure
The Grand Mimic blocks the way. Every test you pass deals damage — pass them all to defeat it and claim a loot chest.
In the treasury vault of the Citadel stands a magnificent iron-bound chest. Adventurers have opened it for centuries — and none of them came back. It is the Grand Mimic, a monster that disguises itself as treasure and swallows the greedy. To defeat it, you must out-count it: catalogue its contents, trade with its hoard, and pack only what you can carry.
Battle plan
The Mimic's treasure is modelled with the three collections from this chapter:
- loot drops arrive as a
string[]— one entry per item found; - the chest itself is a
Dictionary<string, int>mapping an item name to its quantity; - results that grow as you build them are
List<string>s.
Item names are case-sensitive ("gem" and "Gem" are different items). The tests pass in their own dictionaries and check how your methods change them, so modify the given chest in place where the assignment says so.
Assignment
Complete the methods in Program:
CountItems(drops)returns a new dictionary with how often each item appears:["gem", "coin", "gem"]→{ gem: 2, coin: 1 }.AddLoot(chest, item, amount)addsamountofitemto the chest (creating the entry if needed). Anamountof 0 or less changes nothing.TakeLoot(chest, item, amount)removesamountofitemand returnstrue. If the item is missing or there is not enough of it, nothing changes and it returnsfalse. An item whose quantity drops to 0 is removed from the chest.TotalValue(chest, prices)returns the sum of quantity × price over all items. Items without a price are worth 0.RarestItems(chest)returns the names of the items with the smallest quantity, sorted alphabetically — several items can tie. An empty chest gives an empty list.Pack(items, weights, capacity)—items[i]weighsweights[i]. Go through the items in order and pack every item that still fits (total weight ≤capacity); skip the ones that do not and continue with the next. Return the names of the packed items.
Premium lesson
Unlock the full Learn C# course
- All 34 lessons, bosses and quizzes — lifetime access
- One payment of $35, no subscription
- Finish within 30 days and claim $10.50 (30%) back
Want more than one course?
The All-Access Pass unlocks all 8 courses and every new one we release, for $120 once.
Keep learning
Need a quick reminder? The C# cheat sheet has every topic of Learn C# on one page.
Lesson last updated on .