Coin Rolls

Every night, I dump all the change in my pocket into a big bucket.

When I buy things, I never hand over coins. always bills. So I accumulate a lot of coins. Even if the purchase price is $1.01, and I have lots of coins in my pocket, I pay $2 and take the 99 cents in change. All the more coins to dump in my change bucket!

After about 10 years of this, I decide to roll all the coins into rolls. Remember that a quarter roll is $10, a dime roll is $5, nickels $2, pennies 50 cents. So I go to the Banking Supply Store and buy empty paper rolls.

The Banking supply store, conveniently, sells assortment packs of coin rolls. Each assortment pack contains W quarter rolls, X dime rolls, Y nickel rolls, and Z penny rolls.

The question: what is the optimum ratio of W to X to Y to Z to maximize the probability that I will use up the assortment packs at the same rate, e.g. without lots of leftover nickel tubes and stuff?

P.S. this problem should ideally be solved using Excel (but if you really like doing these things by hand, be my guest).

submitted by joel

paul brinkley makes these assumptions which are all good assumptions to make:
Assumption 1: The price of purchases made, modulo $1, is an even distribution from 0 cents to 99 cents.
Assumption 2: The cashier will always give you the least number of coins mathematically possible, and will always have enough of each type of coin to do this. So you’ll never get 99 pennies as change for a $1.01 purchase, for example.
Assumption 3: Half dollars don’t exist.

Solution

“Brute force” approach:

I guess I’ll begin with a few assumptions:

Assumption 1: The price of purchases made, modulo $1, is an even distribution from 0 cents to 99 cents. Probably not true, but we can cover that later.

Assumption 2: The cashier will always give you the least number of coins mathematically possible, and will always have enough of each type of coin to do this. So you’ll never get 99 pennies as change for a $1.01 purchase, for example.

Assumption 3: Half dollars don’t exist.

Over the long haul, then, you’d get N sets of 0 cents, 1 cent, 2 cents, and so on up to 99 cents. So let’s consider one of each. How many of each coin would you end up with?

Easy first: let’s do quarters. 25-49 cents each gets you one. 50-74 each gets you two. 75-99 each gets you three. That’s (1+2+3)*25, or 150 quarters.

Dimes next. 10-19 gets you one. 20-24, two. (You’d get a quarter instead for 25 and up.) 35-44, one. 45-49, two. 60-69, 85-94, one. 70-74, 95-99, two. So that’s 4*(10+5*2), or 80 dimes.

Nickels. One for 5-9, 15-19, and that same pattern for +25, +50, +75, so it’s 4*10 or 40 nickels. You’ll never get two at a time, since a dime (at least) will do.

Pennies. Let’s cut to the chase: 1,2,3, and 4 cents gets 10 pennies in all, and that pattern happens 20 times, so that’s 200 pennies.

Let’s double-check. 200 pennies, 40 nickels, 80 dimes, 150 quarters. That’s 200*1 + 40*5 + 80*10 + 150*25 cents = 200+200+800+3750 = 4950 cents, which is the sum of all numbers from 0 to 99, so it checks.

15/8/4/20 would be the ratio then, IF coin rolls all hold the same number of coins, but they don’t. Quarter rolls hold 40 coins, dime rolls hold 50, nickel rolls 40, penny rolls 50. So you need 5/4 as many quarter and nickel rolls. The final ratio is 75/32/20/80. Seems like a lot of quarters and pennies, except for the assumption that you’ll tend to get them much more often than nickels and dimes as change.

The numbers change slightly when you figure in things like frequency of coins in circulation, the supply the cashier has at any one time, the actual distribution of change values, and the cashier’s inclination to give you two dimes and a nickel instead of a quarter just because…

So what numbers do assortment packs really contain?

💡Strategies for Solving This Problem

Dynamic Programming Coin Problem

Got this at Jane Street in 2023. It's about calculating probabilities with coin rolling, which turns into a DP problem. Tests understanding of probability, recursion, and memoization.

The Problem

You have N coins arranged in a row. You repeatedly pick a random coin and "roll" it - if it shows heads, you remove it. If tails, you leave it. What's the expected number of rolls until all coins are removed?

Simpler Version First

Start with 1 coin: Expected rolls = 2 (need heads, which happens with p=0.5, so E[X] = 1/0.5 = 2)

With 2 coins: More complex. Could remove first coin, then second. Or second, then first. Need to calculate all paths.

Approach 1: Simulation

Run 10,000 trials:

  1. Start with N coins
  2. Pick random coin, flip
  3. If heads, remove it
  4. Count total rolls until all gone
  5. Average across trials

This gives empirical answer but not exact.

Approach 2: Mathematical Analysis

For N coins, let E(N) = expected rolls to remove all N coins.

On each roll:

  • Probability 1/N of picking any specific coin
  • Probability 1/2 that coin shows heads (removed)
  • So probability 1/(2N) of removing any specific coin

Expected rolls to remove first coin: 2N (since p = 1/(2N))

But this gets complex because probability changes as coins are removed.

Approach 3: Recursive Formula with Memoization

E(N) = 1 + (probability we remove a coin) × E(N-1) + (probability no coin removed) × E(N)

Simplify:

  • Probability we remove a coin: N × (1/N) × (1/2) = 1/2
  • Probability no coin removed: 1/2

E(N) = 1 + (1/2)×E(N-1) + (1/2)×E(N)

E(N) - (1/2)×E(N) = 1 + (1/2)×E(N-1)

(1/2)×E(N) = 1 + (1/2)×E(N-1)

E(N) = 2 + E(N-1)

Base case: E(1) = 2

So: E(N) = 2N

Answer: Expected number of rolls = 2N

At Jane Street

I started with simulation. Interviewer asked "Can you derive it mathematically?" I worked through the recursive formula. Then he asked variations - what if coins have different removal probabilities, what if you can choose which coin to roll, etc.

Scroll to Top