Puzzle: how many Christmas trinkets to buy?
I came across a very interesting problem in the math section of reddit. The problem is about a business that wants to decide how much inventory of a product to buy facing an uncertain demand. The business wants enough to maximize profits, but it knows that unsold units will be a loss.
Here is my slight restatement of the original problem
Assume you are running a business that sells a seasonal Christmas trinket. You can buy the trinket at $3 and sell it for $4. You can only buy the trinket once a year and cannot replenish till next year.
From experience, you have some idea about how much product will sell. Every year, the demand for the trinket from your shop will be of an equal probability between 0 and 100 (that is, there is a 1/101 chance that 0 units will sell, a 1/101 chance that 1 unit will sell, …, and a 1/101 chance that 100 units will sell).
You have a choice to buy between 0 and 100 units of the product. After the holiday season is over, no one wants the trinkets, and you’ll have to discard any unused products at your loss.
How many Christmas trinkets should you buy?
Clarification note for the probability: if you buy too few trinkets, then you simply sell out. Let’s say you buy 10 trinkets, but that year the demand happened to be for 100 trinkets. In that case, you sell out of your 10 trinkets, and you missed out on the chance to profit on high demand.
Can you solve it?
Bonus: a generalization of the problem
Once I solved the puzzle, I was curious about the general case. I wanted to know how sensitive the result was to the input parameters: how much did the result depend on the price the product sold (P), the cost of acquiring it (C), and the available supply (S)?
After solving the general case, I noticed a surprising result. The optimal solution is closely tied to the concept of gross margin. (Margin is the profit defined in terms of the price of an item: 1 – C / P. This is slightly different than the markup, which is the percent profit in terms of the cost)
Specifically, the following is true for the general case:
The proportion of the total supply you should buy is roughly equal to the margin of the product
For example, if you can sell a product for $5 and buy it for $3, then you make $2 on a $5 product, so the margin is 40 percent. The rule of thumb says you maximize profits by buying 40 percent of the available supply. (If there are 100 units, then buy 40)
I give the detailed derivation in the rest of this post.
Closing tangent: I was initially so excited by the result I actually wanted to title this puzzle as “optimal inventory management with uncertain demand: why the margin matters.”
But you may see why I did not use such a dull sounding title.
I normally put the answer to the puzzle in the comments, but for today, I changed things up and have included it below.
So note: spoilers below
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Answer to the puzzle
I will break the answer down into a some manageable steps.
Step 1: figuring out the probability distribution
The key to the problem is figuring out the probability distribution if you buy n units.
If you buy all 100 units, then you safely know that you have 1/101 probability of selling each unit. But what if you buy fewer units, like say 50 or 30 units? You have to derive the probability distribution from the theoretical demand.
For all units less than n, the probability that you sell that many units is simply 1/101. But for your last unit, you have to include the instances when people demand more than n units. To do that, you want to add in the probabilities like follows:

I will put the distribution in text as well for reference.
If you buy n units, then the probability you will sell units is given by:
–1/101 chance sell 0 units
–1/101 chance sell 1 unit
–1/101 chance sell 2 units
…
–(101-n)/101 chance sell all n units
The reason the last probability is higher is this: if the demand for units is higher than n, then you only get to sell n units. So you have to lump the probability of selling n or more units into one term.
Step 2: writing the expected profit
The expected profit will be given by the expected revenue (number sold times $4) subtracted by the cost (this part is easy: you spent $3 * n for the units, whether they sell or not).
So the expected profit is given by:
Profit = (selling price)(expected sales) – (cost)(units bought)
Profit = 4(expected sales) – 3n
Profit = 4[1/101 (0 + 1 + 2 + ... + n-1) + (101-n)n/101]- 3n
…
(lots of algebra)
…
Profit = 1/202 (198n – 4n2)
Now that you have the expected profit, the rest of the problem should be straightforward.
Step 3: maximizing profits
The amount you want to buy is the number of units that maximizes profits.
To maximize profits, we take the derivative of the profit equation and set it equal to zero. Then we verify the amount we solved for is a maximum.
Or, we can just use WolframAlpha to do it for us:
Since we cannot buy fractional amounts, we need to check whether 24 or 25 is the right answer. You can find that 25 gives the maximum of $12.13 of expected profit.
In the end of the day, you ultimately want to hedge your bet and not buy too much of the supply. You buy a decent amount so you can meet demand, but if you buy too much you’ll end up taking a hit on the loss.
The extension of the problem
When I solved the problem, I was curious if it meant anything that the optimal answer was buying 25 percent of the available supply.
I noticed that 25 percent was related to the margin: you make $1 profit on a $4 product, so that’s a 25 percent margin.
This turns out to be exactly the case. Here’s the general case.
Let’s suppose you can sell a product for P, you buy it for C, and the available supply is S. Additionally, the demand for the product is given by:
–1/(S+1) chance sell 0 units
–1/(S+1) chance sell 1 unit
–1/(S+1) chance sell 2 units
…
–(S-n+1)/(S+1) chance sell S units
We can proceed as above to find out the expected profit of buying n units with these conditions.
I will spare you the algebra and just cut to the answer. The optimal number of units to buy is:
optimal number = S(1 – C/P) – 0.5 + (1 – C/P)
Now we have the answer, let’s interpret it.
The first thing we can do is ignore the additive term 0.5 + (1 – C/P). Both of these are fractions, so the term will be between 0 and 1. Ultimately this will only affect the optimal answer by 1 unit, so for the sake of estimating, let’s ignore this term.
So what we end up with is this:
optimal number esimate = S (1 – C/P)
The answer can be interpreted as follows: you should buy a percentage of supply equal to the term (1 – C/P).
And what is that term (1 – C/P)? This is precisely the margin of the product: it’s the amount of profit you make as a percentage of the price of the product.
In other words, the percentage amount of supply you should buy is equal to the margin of the product. That’s quite a big simplification considering all the optimization math you see above.
Another implication of the model is this: you’ll rarely want to buy all of the available supply, unless your margin is off the wall. Like if you could buy something at $1 and sell it for $100, then you’re at a point where it could make sense to buy all the supply.
I love it when math works out so nicely.
Share this post:
Previous post: Poll results: debit card use
Next post: Auction theory puzzle: finding the right number of bidders




