KatInterview

Product of Three Dice: Summary Statistics Report

Math & Bit ManipulationAuto-graded · 2 test cases
EasyAuto-gradedMath & Bit Manipulationenumerationprobabilitycounting

Last updated

Enumerate all 216 outcomes of three dice to compute the mean, modes, prime probability and median of their product, and return a fixed risk note.

Product of Three Dice

Three fair six-sided dice, each showing an integer from 1 to 6, are rolled independently. Let the random variable P be the product of the three faces.

Write a function that takes no arguments and returns a dictionary summarizing the distribution of P. Treat the sample space as the 216 equally likely ordered outcomes (a, b, c) with each of a, b, c in 1..6.

Required keys

The returned dictionary must contain exactly these five keys:

  1. "expected_value": the mean of P over all 216 outcomes, as a float.
  2. "modes": a list of every value of P that occurs most often among the 216 ordered outcomes, sorted in ascending order. Each element is an int.
  3. "prime_probability": the probability that P is a prime number, as a float. This is the number of outcomes whose product is prime divided by 216. Recall that 1 is not prime.
  4. "median": the median of P as an int. Sort the 216 products in ascending order and take the element at zero-based position 108 (the 109th smallest value). This value m satisfies both P(P <= m) >= 0.5 and P(P >= m) >= 0.5.
  5. "skewness": a fixed text note about a seller who sells the derivative at the price E[P]. It must be exactly this string, character for character:
right-skewed; outcomes substantially above the expected sale price are possible, creating adverse upside exposure for the seller

Context

Imagine you sell a derivative whose payoff is exactly P at a fixed price equal to E[P]. The statistics above describe how the payoff is distributed. The fixed "skewness" text summarizes the resulting risk for the seller.

Constraints

  • Each die is fair and independent of the others.
  • Use exact enumeration over the 6^3 = 216 ordered outcomes. Different orderings of the same faces count as different outcomes.
  • The function takes no parameters.
  • The returned dictionary has exactly the five keys listed above.

Examples

Example 1

Input: summarize_dice_product()

Output: {'expected_value': 42.875, 'modes': [12, 24], 'prime_probability': 0.041666666666666664, 'median': 30, 'skewness': 'right-skewed; outcomes substantially above the expected sale price are possible, creating adverse upside exposure for the seller'}

Hints

Hint 1

There are only 216 ordered outcomes, so you can enumerate all of them with three nested loops and build a list of products.

Hint 2

A Counter of the products gives the frequency of each value. Take the maximum frequency and collect every value that reaches it, then sort them.

Hint 3

A product of three integers that are each at least 1 can only be prime if two of the factors are 1. Alternatively, test each product directly against a small primality check. For the median, sort the products and read the element at index 108.