Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-034

Two Dice Sum Distribution

Problem

Return the probability distribution of the sum of two independent fair dice, each with the given number of sides.

The result is a list giving P(sum = 2), P(sum = 3), ..., P(sum = 2 * sides). Return an empty list for sides <= 0.

Hint

The number of ways to roll sum s rises to a plateau then falls symmetrically.

Test cases

case 1
in: [6]
expected: [0.027777777777777776,0.05555555555555555,0.08333333333333333,0.1111111111111111,0.1388888888888889,0.16666666666666666,0.1388888888888889,0.1111111111111111,0.…
case 2
in: [2]
expected: [0.25,0.5,0.25]
case 3
in: [1]
expected: [1]
Starter codePython
def two_dice_sum_distribution(sides):
    # Your code here
    pass

3 test cases · run your code against them in the editor