KatInterview

Dice Duel Wager: Expected Profit and Play Decision

Math & Bit ManipulationAuto-graded · 18 test cases
EasyAuto-gradedMath & Bit Manipulationprobabilityexpected-valuemath

Last updated

Compute the expected profit of a two-dice wager where ties favor the opponent, and decide whether a risk-neutral player should accept it.

You are offered a wager against an opponent. You and the opponent each roll one fair six-sided die exactly once. The two rolls are independent, and every face from 1 to 6 is equally likely for each die.

The payment rules are:

  • If your roll is strictly greater than the opponent's roll, the opponent pays you win_amount dollars.
  • Otherwise (your roll is smaller than or equal to the opponent's roll), you pay the opponent loss_amount dollars.

Write a function that computes your expected profit from a single round and decides whether a risk-neutral player should accept the wager.

Task

Given win_amount and loss_amount, return a dictionary with exactly two keys:

  • "expected_value": the expected profit (in dollars) of one round, from your point of view. A loss counts as negative profit.
  • "should_play": a boolean that is True only if the expected profit is strictly greater than zero. If the expected profit is exactly zero or negative, it is False.

Notes

  • Ties are always losses for you, so they use the loss_amount payment.
  • The expected value should be computed from the exact probabilities of the 36 equally likely ordered roll pairs.
  • At the break-even point the expected value is zero and the answer to whether to play is False.

Constraints

  • win_amount and loss_amount are non-negative numbers (integers or floats).
  • Both dice are fair, six-sided, and independent.
  • The returned dictionary must contain exactly the keys "expected_value" and "should_play".

Examples

Example 1

Input: dice_wager_decision(10, 5)

Output: {'expected_value': 1.25, 'should_play': True}

Example 2

Input: dice_wager_decision(7, 5)

Output: {'expected_value': 0, 'should_play': False}

Example 3

Input: dice_wager_decision(14, 10)

Output: {'expected_value': 0, 'should_play': False}

Hints

Hint 1

List all 36 ordered pairs of rolls. How many of them have your roll strictly greater than the opponent's roll? Remember that each pair has the same probability.

Hint 2

Ties (6 pairs) count as losses for you, so the loss payment applies to 15 + 6 = 21 outcomes, while the win payment applies to 15 outcomes.

Hint 3

The expected profit is (15 * win_amount - 21 * loss_amount) / 36. Play only when this is strictly positive, so a break-even game returns False.