Pricing Two Coin-Editing Tools in a Four-Coin Game
Math & Bit ManipulationAuto-graded · 13 test casesLast updated
Compute a baseline expected payoff and the fair prices of two coin-editing tools, using linearity of expectation, a parity invariant, and an absorbing-state argument.
Four-Coin Game and Two Tools
In a game, four fair coins are tossed together and you receive $1 for every coin that ends up showing heads. You are risk-neutral. A tool is offered that lets you modify the coins after you see the first toss. You are asked to value two different tools.
Rules
- The coins are fair and independent, so each shows heads with probability 1/2.
- Your final payoff is $1 per head showing when you stop. There are no other costs or payoffs.
- A tool is used only after you have seen the initial toss. You may use it any number of times, every use is free, and you choose when to stop and collect.
- A "pair" is any two distinct coins of your choice. You may pick a different pair on each use, based on the current state of the coins (fully adaptive play).
- The fair price of a tool is the increase in your expected payoff from owning it, assuming you play optimally.
Task
Write a function that takes no arguments and returns a list of three numbers, in this order:
- The expected payoff of the game with no tool.
- The fair price of the flip tool: each use selects a pair of coins and turns both over deterministically (heads becomes tails and tails becomes heads).
- The fair price of the re-toss tool: each use selects a pair of coins and tosses both of them again.
Return plain numbers, so the result for this problem is a list of three floats (or ints that equal them numerically).
Constraints
- Exactly four coins, all fair and independent.
- Payoff is $1 per head at the time you stop.
- Tool uses are free and unlimited, and you act adaptively after seeing the coins.
- The prices are measured relative to the no-tool expected payoff.
- The function takes no input and always returns the same three values.
Examples
Example 1
Input: coin_tool_prices()
Output: [2, 1.5, 2]
Hints
Hint 1
Use linearity of expectation for the baseline: each coin contributes the same expected amount, so you do not need to enumerate outcomes.
Hint 2
For the flip tool, look at how a single use changes the number of heads. Is there a quantity that can never change? Then ask which head counts are reachable from each starting class.
Hint 3
For the re-toss tool, the head count can drop temporarily, but uses are free and unlimited. Think about whether the state with all heads can always be reached eventually, and what that implies for the best possible payoff.
Worked solution
Easy Try it yourself first — then compare your approach, complexity and edge cases.
Approach
This is a reasoning problem, so the code only assembles three closed-form results.
1. Baseline
Let each coin contribute 1 if it shows heads and 0 otherwise. By linearity of expectation, the expected payoff is 4 × 1/2 = 2.
2. Flip tool
Flipping two coins changes the head count by -2 (two heads become tails), +2 (two tails become heads), or 0 (one of each). The change is always even, so the parity of the head count is invariant.
- If the starting head count is even (0, 2 or 4), the number of tails is even. Pair the tails up and flip each pair to reach 4 heads. This covers 1 + 6 + 1 = 8 of the 16 equally likely outcomes.
- If the starting head count is odd (1 or 3), 4 heads is unreachable. 3 heads is reachable, because the tail count is odd: pair up all tails but one. This covers 4 + 4 = 8 of the 16 outcomes.
Expected payoff with the tool is (8·4 + 8·3) / 16 = 3.5, so the fair price is 3.5 - 2 = 1.5.
3. Re-toss tool
The payoff can never exceed 4, so the question is whether 4 heads can be reached with probability 1.
- With two or more tails showing, re-toss two tails. Neither coin can get worse, so this step carries no risk.
- With exactly one tail (3 heads), re-toss the tail together with a head. The result is 4 heads with probability 1/4, 3 heads with probability 1/2, and 2 heads with probability 1/4. A drop to 2 heads is only temporary, since you can re-toss the two tails next.
The head count forms a finite Markov chain in which 4 heads is absorbing and reachable with positive probability from every state. So it is reached with probability 1, and since uses are free and unlimited, the expected payoff is 4. The fair price is 4 - 2 = 2.
The re-toss tool beats the flip tool because randomness breaks the parity invariant.
Complexity
Time O(1) and space O(1), since the function returns fixed values.
Reference solution
from typing import List
def coin_tool_prices() -> List[float]:
# No tool: linearity of expectation, 4 coins * 1/2 each.
baseline = 2.0
# Flip tool: the parity of the head count never changes.
# Even head counts (8 of 16 outcomes) can all be raised to 4 heads.
# Odd head counts (8 of 16 outcomes) can be raised to 3 heads at best.
flip_value = (4 * 8 + 3 * 8) / 16 # 3.5
# Re-toss tool: repeat until all four coins show heads; this happens
# with probability 1, so the expected payoff is 4.
retoss_value = 4.0
return [baseline, flip_value - baseline, retoss_value - baseline]