返回题库

条件骰子

Conditional Die Rolls

专题
Probability / 概率
难度
L4

第 1 小问

题目详情

Dan 掷骰子,直到获得 66。鉴于他“没有”看到 55,Dan 掷骰子的预期次数是多少?

Dan rolls a dice until he gets a 66. Given that he did not see a 55, what is the expected number of times Dan rolled his die?

解析

如果 Dan 没有看到 55,则意味着条件是 6655 之前出现。当掷一个公平的骰子时,这种情况会发生一半,因此该情况​​的概率为 12\frac12

给定条件下滚动 66 的概率为 1612=13\frac{\frac16}{\frac12} = \frac13。因为卷是彼此独立的,所以该分布是 p=13p = \frac13 的几何分布,结果是: μ=1p=3\mu = \frac1p = \boxed3 (请注意,如果他没有看到 55,则滚动 66 的概率不是 15\frac15。这表明 Dan 滚动 1,2,3,4,1,2,3,4,66 的可能性相同,这不可能是真的,因为你知道 66 出现在 55 之前,而其他数字不一定是这种情况)

import random

roll_dice = lambda: random.randint(1,6)

sequence_lengths = []
num_iters = 10_000
for i in range(num_iters):

    sequence = []
    while(True):

        sequence.append(roll_dice())

        if sequence[-1] == 5:
            break
        elif sequence[-1] == 6:
            sequence_lengths.append(len(sequence))
            break

print(sum(sequence_lengths)/len(sequence_lengths))

Original Explanation

If Dan did not see a 55, that means the condition is 66 came before 55. When rolling a fair dice, this will occur half the time, thus the probability of the condition is 12\frac12.

The probability of rolling a 66 given the condition is 1612=13\frac{\frac16}{\frac12} = \frac13. Because rolls are independent of each other, this distribution is geometric with p=13p = \frac13 resulting in: μ=1p=3\mu = \frac1p = \boxed3

(Note if he does not see 55 the probability of rolling a 66 is not 15\frac15. That suggests Dan is equally likely to roll a 1,2,3,4,1,2,3,4, and 66 which can not be true since you know 66 comes before 55 which is not necessarily the case with the other numbers)

import random

roll_dice = lambda: random.randint(1,6)

sequence_lengths = []
num_iters = 10_000
for i in range(num_iters):

    sequence = []
    while(True):

        sequence.append(roll_dice())

        if sequence[-1] == 5:
            break
        elif sequence[-1] == 6:
            sequence_lengths.append(len(sequence))
            break

print(sum(sequence_lengths)/len(sequence_lengths))

第 2 小问

题目详情

Dan 掷骰子,直到获得 66。鉴于他看到了 55,Dan 掷骰子的预期次数是多少?

Dan rolls a dice until he gets a 66. Given that he saw a 55, what is the expected number of times Dan rolled his die?

解析

这与第 1 部分的情况相反,其中第一个 55 在第一个 66 之前出现。使用第 1 部分,我们知道找到预期的卷数,看到第一个 5533

一旦我们看到了第一个55,就没有更多的条件了。当没有条件时,滚动 66 的概率就是 16\frac16,因此我们期望在看到第一个 66 之前滚动骰子 66 次。要消除这种情况,平均需要掷 33 次,一旦这种情况消失,我们预计会掷 66 次,因此 Dan 预计会掷骰子 9\boxed9 次。

import random

roll_dice = lambda: random.randint(1,6)

sequence_lengths = []
num_iters = 10_000
for i in range(num_iters):

    sequence = []
    while(True):

        sequence.append(roll_dice())

        if sequence[-1] == 6:
            if 5 in sequence:
                sequence_lengths.append(len(sequence))
            break

print(sum(sequence_lengths)/len(sequence_lengths))

Original Explanation

This is the opposite case as Part 1 where the first 55 is seen before the first 66. Using Part 1, we know find the expected number of rolls to see the first 55 is 33.

Once we have seen the first 55, there is no more condition. When there is no condition, the probability of rolling a 66 is simply 16\frac16 so we expect to roll a die 66 times before seeing our first 66. To get rid of the condition will take on average 33 rolls and once the condition is gone we expect to roll 66 times therefore Dan can expect to roll the die 9\boxed9 times.

import random

roll_dice = lambda: random.randint(1,6)

sequence_lengths = []
num_iters = 10_000
for i in range(num_iters):

    sequence = []
    while(True):

        sequence.append(roll_dice())

        if sequence[-1] == 6:
            if 5 in sequence:
                sequence_lengths.append(len(sequence))
            break

print(sum(sequence_lengths)/len(sequence_lengths))

第 3 小问

题目详情

Dan 掷骰子,直到获得 66。鉴于他只看到偶数,丹掷骰子的预期次数是多少?

Dan rolls a dice until he gets a 66. Given that he saw only even numbers, what is the expected number of times Dan rolled his die?

解析

仅看到偶数意味着 66 出现在 1,3,1, 3,55 之前。 44 总数中第一个出现的单个数字的出现概率为 14\frac14,因此该条件的概率为 14\frac14

使用与第 1 部分类似的逻辑,我们得到在给定的滚动中将 66 滚动为 1614=23\frac{\frac16}{\frac14} = \frac23 的概率,因此: μ=32\mu = \boxed{\frac32}

import random

roll_dice = lambda: random.randint(1,6)

sequence_lengths = []
num_iters = 10_000

for i in range(num_iters):
    sequence = []

    while(True):
        sequence.append(roll_dice())

        if sequence[-1] == 1:
            break
        elif sequence[-1] == 3:
            break
        elif sequence[-1] == 5:
            break
        elif sequence[-1] == 6:
            sequence_lengths.append(len(sequence))
            break

print(sum(sequence_lengths)/len(sequence_lengths))

Original Explanation

Seeing only even numbers means 66 came before 1,3,1, 3, and 55. A single number coming first among 44 total numbers has probability 14\frac14 of occuring, thus the probability of the condition is 14\frac14.

Using similar logic to Part 1 we get the probability of rolling a 66 in a given roll to be 1614=23\frac{\frac16}{\frac14} = \frac23, thus:

μ=32\mu = \boxed{\frac32}
import random

roll_dice = lambda: random.randint(1,6)

sequence_lengths = []
num_iters = 10_000

for i in range(num_iters):
    sequence = []

    while(True):
        sequence.append(roll_dice())

        if sequence[-1] == 1:
            break
        elif sequence[-1] == 3:
            break
        elif sequence[-1] == 5:
            break
        elif sequence[-1] == 6:
            sequence_lengths.append(len(sequence))
            break

print(sum(sequence_lengths)/len(sequence_lengths))