All problems
Expected Maximum of Two Dice
Problem
Return the expected maximum of two independent fair dice, each with the given number of sides.
E[max] = sum over k of k * (2k - 1) / sides^2, which simplifies to (sides + 1) * (4 * sides - 1) / (6 * sides). Return 0.0 for sides <= 0.
Hint
P(max = k) = (2k - 1) / sides^2 for two independent fair dice.
Test cases
case 1
in: [6]
expected: 4.472222222222222
case 2
in: [2]
expected: 1.75
case 3
in: [1]
expected: 1
Starter codePython
def expected_max_two_dice(sides):
# Your code here
pass3 test cases · run your code against them in the editor