5078

Mixed-Case Bundle Pricing

Algorithm
Hard
Pro
recursion
memoization
optimization
discounts

Mixed-Case Bundle Pricing

Marketing has launched a "mixed case" promotion: every unit sells at the same list price, but a bundle of different SKUs earns a discount that grows with the variety in the bundle. The checkout must charge the customer the cheapest total that any arrangement of their basket allows — and as every veteran of this pricing scheme knows, the obvious arrangement is not always the cheapest one.

Requirements

The starter ships a table named "Bundle Basket Line" — the in-memory basket your code prices. Keep its fields and key exactly as shipped; the grading tests seed it directly:

  • "SKU Code" — Code[20], the primary key: one line per distinct SKU
  • Quantity — Integer, how many units of that SKU are in the basket

Complete the codeunit named "Bundle Pricing" with one public procedure:

procedure MinimalTotal(var BasketLine: Record "Bundle Basket Line"; UnitPrice: Decimal): Decimal

Rules:

  1. Every unit in the basket has the same list price, UnitPrice.
  2. A bundle is a group of 1 to 5 units whose SKUs are pairwise distinct — a bundle can never contain two units of the same SKU.
  3. A bundle's price is the sum of its units' list prices minus a discount that depends only on the bundle's size: 1 unit — no discount, 2 units — 5%, 3 units — 10%, 4 units — 20%, 5 units — 25%. So a bundle of k units costs k × UnitPrice × (100 − discount%) / 100.
The rest of the statement and 3 hints Unlock with Pro
ALBusiness Central 28.5
Pro
Pro problem

Solve it with Pro

You’re reading the opening of the statement. Pro unlocks the whole problem:

  • The full statement
  • Starter code in the browser editor
  • 12 grading tests, run on Business Central 28.5
  • 3 hints
  • The reference solution

Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.

$10 / month
or $100 / year
Upgrade
This problem is part of Pro
Pro unlocks the full statement, tests, hints and solution. The code editor works on a computer.
Upgrade