KatInterview

Is This Dice Wager Worth Playing? Expected Value Check

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

Last 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_amount dollars.
  • Otherwise, meaning the dealer's number is greater or the two numbers are equal, you pay the dealer lose_amount dollars.

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 is True in that case.

The dictionary must use exactly the keys "expected_value" and "should_play".

Constraints

  • win_amount and lose_amount are 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.