avatar Bite 365. Rolling two dice for an advantage

Let's roll the dice!

When playing a game where it is beneficial to roll a higher value, a player can gain an advantage by rolling two dice simultaneously and choosing the die with the higher value. This has to do with the expected value which can be thought of as the average value of a die.

To calculate the expected value, you multiply the value of each possible outcome by the probability of obtaining that outcome. For example, for a 6-sided die, each outcome has a probability of 1/6 because all outcomes are equally likely and there are six outcomes in total. The expected value, __E__, of a 6-sided die is:

However, the expected value changes when you roll two dice simultaneously and choose the higher value. Looking at the 6-sided die again, all possible outcomes are shown in the table below:

  1 2 3 4 5 6
1 (1,1) (1,2) (1,3) (1,4) (1,5) (1,6) 
2 (2,3) (2,2)  (2,3) (2,4) (2,5) (2,6)
3 (3,1)  (3,2) (3,3) (3,4) (3,5) (3,6)
4 (4,1) (4,2) (4,3) (4,4) (4,5) (4,6)
5 (5,1)  (5,2) (5,3) (5,4) (5,5) (5,6)
6 (6,1) (6,2) (6,3) (6,4) (6,5) (6,6)


Now there is only one way to get a 1 (probability of 1/36), but there are 11 ways to roll a six (probability of 11/36). So the expected value of rolling two 6-sided dice and choosing the larger one is:

Your Task

This Bite has two parts:

1. What is the expected value for an n-sided die?

2. What is the new expected value for an n-sided die when rolling two dice simultaneously and choosing the higher value (rounded to 3 decimal places)?

Keep calm and code in Python!

Login and get coding
go back Intermediate level
Bitecoin 3X

13 out of 16 users completed this Bite.
Will you be Pythonista #14 to crack this Bite?
Resolution time: ~30 min. (avg. submissions of 5-240 min.)

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help