The core mechanic clicked fast for me, tally up owned cards by color, subtract from the cost, clamp at zero.
First, clarify the data model: each card has a color and a gem cost per color, and each card in hand provides a -1 discount to future purchases of its color. Then, derive the effective cost for each color as max(0, base_cost - discount[color]), and update the affordability check to compare total effective cost against owned gems. Finally, update the purchase logic to deduct the effective cost and add the purchased card to the hand, ensuring discounts are recalculated for subsequent purchases.
Pro tip: Mention that discounts should be computed dynamically from the current hand, and consider edge cases like multiple cards of the same color and the no-floor-below-zero rule to show thoroughness.
Define the structures for cards, gems, and hand. Each card has a color and a cost map (color -> gem count). The hand is a collection of cards, and owned gems is a map (color -> count).
For each color, count the number of cards in hand of that color. The discount for that color is that count (each card gives -1).
For a given card, its effective cost per color is max(0, base_cost[color] - discount[color]). The total effective cost is the sum over all colors.
A card is affordable if for every color, owned_gems[color] >= effective_cost[color]. (Alternatively, check total effective cost <= total owned gems, but per-color check is more precise.)
If affordable, deduct the effective cost from owned gems per color, and add the purchased card to the hand. Recompute discounts for future purchases.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.