重复掷骰
Repeated Rolling
第 1 小问
题目详情
假设一个游戏要求你重复掷出一个公平的六面骰子,直到你第一次遇到以前出现过的数字。设 表示骰子滚动的次数, 表示滚动 次的概率。
第 1 部分
计算。
Suppose a game has you roll a fair six-sided die repeatedly, until you first encounter a number which has previously appeared. Let denote number of times the die was rolled, and the probability of rolling times.
Part 1
Calculate .
解析
为了使 等于 1,第一次掷骰必须是已经掷出的值。由于这种情况不可能发生,
为了使 等于 2,游戏必须在第二次掷骰时终止,这意味着第二次掷骰必须等于第一次掷骰的值。对于第一掷的给定值 ,第二掷也显示 的概率是 ,看看我们如何掷出公平的骰子。
要使 等于 3,必须满足两个条件。第一卷和第二卷必须不同,第三卷必须等于第一卷或第二卷的值。为了使 等于 3,这些事件中的每一个都必须完全按照描述发生。由于这些事件连续发生,并且每次掷骰的结果都是独立事件,因此我们可以将每个事件的概率相乘:
P(第一卷 = ) P(第二卷 = ) P(第三卷 或 ) =
Original Explanation
In order for to equal 1, the first roll would have to be a value that had already been rolled. Since this cannot occur,
For to equal 2, the game must terminate on the second roll, meaning the second roll would have to equal the value of the first roll. For a given value of the first roll, the probability that the second roll also shows , is , seeing as how we’re rolling a fair die.
For to equal 3, two conditions must be met. The first and second roll must differ, and the third roll must equal either the value of the first or second roll. Each of these events must happen exactly as described in order for to equal 3. Since these events occur in succession and the outcome of each roll is an independent event, we can multiply the probability of each:
P(first roll = ) P(second roll = ) P(third roll either or ) =
第 2 小问
题目详情
假设一个游戏要求你重复掷出一个公平的六面骰子,直到你第一次遇到以前出现过的数字。设 表示骰子滚动的次数, 表示滚动 次的概率。
第 2 部分
的价值是多少?
Suppose a game has you roll a fair six-sided die repeatedly, until you first encounter a number which has previously appeared. Let denote number of times the die was rolled, and the probability of rolling times.
Part 2
What is the value of ?
解析
该总和对应于 1、2、3、…10 次滚动查看重复值的组合概率。但经过检查,我们可以发现,永远不会需要 10 卷才能看到重复的值。看到重复值所需的最大滚动次数由以下假设给出:
$\def\arraystretch{1.5} \begin{array}{c:c} \text{卷号} & \text{卷结果}\ \hline 1 & 4 \ \hline 2 & 3 \ \hline 3 & 1 \ \hline 4 & 2 \ \hline 5 & 5 \ \hline 6 & 6 \ \hline 7 & ? \end{array}$
正如你所看到的,经过 6 次滚动后,我们仍然没有看到重复值。然而,第七卷保证会显示已经出现的一个。因此,最大的 可能是 7,并且 跨越整个结果空间。任何更高的值,例如 根本不会发生,因此 、 或 都等于 0。因此,这个问题简化为 的总和( 因为它也不可能在第一卷中观察到重复的结果)。由于这六个不相交的事件跨越整个结果空间,因此这些事件的并集概率为 1。
Original Explanation
This sum corresponds to the combined probability of taking 1, 2, 3, … 10 rolls to see a repeated value. But upon inspection, we can see that it will never take 10 rolls to see a repeated value. The maximum number of rolls it could take to see a repeated value is given by the following hypothetical:
$\def\arraystretch{1.5} \begin{array}{c:c} \text{Roll Number} & \text{Roll Outcome}\ \hline 1 & 4 \ \hline 2 & 3 \ \hline 3 & 1 \ \hline 4 & 2 \ \hline 5 & 5 \ \hline 6 & 6 \ \hline 7 & ? \end{array}$
As you can see, after 6 rolls we still have not yet seen a repeated value. However the 7th roll is guaranteed to show one which has already appeared. Therefore, the largest could be is 7, and spans the entire outcome space. Anything higher, such as simply cannot occur and therefore , , or all equal 0. As a result, this question reduces to the sum of ( because it's also impossible to observe a repeated outcome on the first roll). Since these six disjoint events span the entire outcome space, the probability of the union of these events is 1.
第 3 小问
题目详情
假设一个游戏要求你重复掷出一个公平的六面骰子,直到你第一次遇到以前出现过的数字。设 表示骰子滚动的次数, 表示滚动 次的概率。
第 3 部分
鉴于游戏的本次迭代至少进行了 3 轮, 是什么?
Suppose a game has you roll a fair six-sided die repeatedly, until you first encounter a number which has previously appeared. Let denote number of times the die was rolled, and the probability of rolling times.
Part 3
What is given that this iteration of the game has taken at least 3 rolls?
解析
这是贝叶斯规则的一个相当简单的应用。我们被要求计算给定游戏恰好进行 5 次掷骰的概率,假设它至少需要 3 次掷骰。我们可以将其分为两个事件, 5 卷, 至少 3 卷。贝叶斯法则指出: 我们可以分别计算每一项的概率。 简化为 ,只是因为 A 是 B 的真子集。如果 A 发生,B 发生的概率为 1。所以我们剩下来计算 。 可以根据上一个问题的类似过程进行计算,结果为: 由不相交事件 和 组成。我们可以将这些单独相加来计算 ,或者可以使用补码规则来找到该事件不发生的概率。 “至少 3 卷”的补码是“恰好 2 卷”。这是因为整个结果空间被划分为“至少 3 次掷骰”和“恰好 2 次掷骰”事件。因此: 计算 P(A) 和 P(B) 后,我们可以连接两个表达式以获得最终概率: 这是之前解决方案的代码模拟:
import random
# simulate a single dice roll
def roll():
return random.randint(1, 6)
# return number of rolls in a single trial of game
def simulate_game():
seen = []
while True:
roll_ = roll()
if roll_ in seen:
return len(seen) + 1
else:
seen.append(roll_)
# simulate game 10,000 times to verify part c
results = []
for i in range(10000):
res = simulate_game()
if res >= 3: # only add result if at least 3
results.append(res)
num_fives = len([i for i in results if i == 5]) # number of fives
num_results = len(results) # number of results >= 3
print(num_fives / num_results)Original Explanation
This is a fairly straightforward application of Bayes Rule. We are asked to compute the probability of a given game taking exactly 5 rolls, given that it will take at least 3 rolls. We can divide this into two events, 5 rolls, and at least 3 rolls. Bayes’ Rule states:
We can them compute the probability of each term separately. reduces to , simply because A is a proper subset of B. If A happens, B occurs with probability 1. So we are left to compute . can be computed according to a similar process for the previous problem, and results in:
consists of disjoint events and . We could sum these all up individually to compute , or could use the complement rule to find the probability of this event not occurring. The complement of ‘at least 3 rolls’ is ‘exactly 2 rolls’. This is because the entire outcome space is partitioned into the events 'at least 3 rolls' and 'exactly 2 rolls'. Therefore:
After computing P(A) and P(B), we can concatenate the two expressions to get our final probability:
Here's a code simulation for the previous solutions:
import random
# simulate a single dice roll
def roll():
return random.randint(1, 6)
# return number of rolls in a single trial of game
def simulate_game():
seen = []
while True:
roll_ = roll()
if roll_ in seen:
return len(seen) + 1
else:
seen.append(roll_)
# simulate game 10,000 times to verify part c
results = []
for i in range(10000):
res = simulate_game()
if res >= 3: # only add result if at least 3
results.append(res)
num_fives = len([i for i in results if i == 5]) # number of fives
num_results = len(results) # number of results >= 3
print(num_fives / num_results)