KatInterview

Calculate Expected Return from Two Six-Sided Dice

Math & Bit ManipulationAuto-graded · 17 test cases
EasyAuto-gradedMath & Bit Manipulationmath-bitsprobabilitysimulation

Last updated

Computes the expected payoff of a game played with two independent six-sided dice, rounded to two decimal places.

Consider a probability game played with two fair, standard six-sided dice (with faces numbered 1 through 6).

The payoff rules for a single roll of both dice are defined as follows:

  • If both dice display different values, your payout is the greater of the two face values.
  • If both dice land on the same value (a matching pair), you lose an amount equal to the total sum of the two dice (i.e., a payout of $-(a + b)$ for outcome $(a, b)$).

Write a function calculate_expected_payoff that determines the expected value (mean outcome) of the payoff for a single round of this game. Return the expected value rounded to two decimal places.

Constraints

  • The dice are standard six-sided dice with face values $1, 2, 3, 4, 5, 6$.
  • Both dice are independent and fair, yielding 36 equally likely outcomes.

Examples

Example 1

Input: calculate_expected_payoff()

Output: 2.72

Example 2

Input: calculate_expected_payoff()

Output: 2.72

Hints

Hint 1

Identify the total number of equally likely outcomes when rolling two 6-sided dice.

Hint 2

Divide the outcomes into two cases: matching outcomes (6 pairs) and non-matching outcomes (30 pairs).

Hint 3

Sum the payout for every outcome, then divide by 36 and round to 2 decimal places.