Is This Dice Wager Worth Playing? Expected Value Check
Math & Bit ManipulationAuto-graded · 21 test casesLast updated
Count outcomes of a two-dice contest where ties favor the house, compute the expected profit per round, and decide whether a risk-neutral player should take the bet.
Dice Wager
A casino offers a one-round game with two fair six-sided dice. You roll one die and the dealer rolls the other. Both dice are independent, and each face from 1 to 6 is equally likely.
Payouts:
- If your number is strictly greater than the dealer's number, the dealer pays you
win_amountdollars. - Otherwise, meaning the dealer's number is greater or the two numbers are equal, you pay the dealer
lose_amountdollars.
Your net profit for one round is therefore +win_amount or -lose_amount.
Task
Write a function that takes win_amount and lose_amount and returns a dictionary with two entries:
"expected_value": the expected net profit of one round, as a number."should_play": a boolean saying whether a risk-neutral player should accept the game. A risk-neutral player accepts whenever the expected value is greater than or equal to zero. A break-even game (expected value exactly 0) counts as playable, so the value isTruein that case.
The dictionary must use exactly the keys "expected_value" and "should_play".
Constraints
win_amountandlose_amountare positive integers.1 <= win_amount, lose_amount <= 10^9- The dice are fair, and the 36 ordered pairs of rolls are equally likely.
- Ties are always losses for you.
Examples
Example 1
Input: dice_wager_analysis(7, 5)
Output: {'expected_value': 0, 'should_play': True}
Example 2
Input: dice_wager_analysis(14, 10)
Output: {'expected_value': 0, 'should_play': True}
Example 3
Input: dice_wager_analysis(10, 10)
Output: {'expected_value': -1.6666666666666667, 'should_play': False}
Hints
Hint 1
List all 36 ordered pairs of rolls. How many are ties, and how many of the remaining ones favor you?
Hint 2
Since ties go to the dealer, your winning probability is 15/36 and your losing probability is 21/36. Combine these with the two payoffs to get the expected value.
Hint 3
Express the expected value as a single fraction over 12, then decide using the sign of the numerator. Remember that an expected value of exactly zero still means you should play.
Worked solution
Easy Try it yourself first — then compare your approach, complexity and edge cases.
Approach
Two dice give 6 x 6 = 36 equally likely ordered outcomes.
- Ties: 6 outcomes (1-1 through 6-6).
- Non-ties: 30 outcomes. By symmetry, the two players are equally likely to be higher, so 15 outcomes favor you and 15 favor the dealer.
Because ties count as losses for you:
- P(win) = 15/36 = 5/12
- P(lose) = 21/36 = 7/12
The expected profit of one round is
E = (5/12) * win_amount - (7/12) * lose_amount = (5 * win_amount - 7 * lose_amount) / 12
A risk-neutral player simply maximizes expected profit, so they play exactly when E >= 0. This is equivalent to win_amount / lose_amount >= 7/5. At equality the game is break-even, and by the stated rule it counts as playable.
Why it is correct
The counting covers every outcome exactly once. The symmetry argument is valid because swapping the two dice maps "you higher" outcomes to "dealer higher" outcomes one-to-one. The expected value is then just the probability-weighted sum of the two payoffs.
Common pitfall: treating ties as pushes or using P(win) = 1/2 gives the wrong threshold (win_amount > lose_amount). Under these rules an even-money bet has expected value -lose_amount / 6.
Complexity
Time O(1) and space O(1), since the result is a closed-form formula.
Reference solution
from typing import Dict
def dice_wager_analysis(win_amount: int, lose_amount: int) -> Dict[str, object]:
# Out of 36 equally likely pairs: 15 wins for you, 21 losses (15 + 6 ties).
expected_value = (5 * win_amount - 7 * lose_amount) / 12
return {
"expected_value": expected_value,
"should_play": expected_value >= 0,
}