最高点数期望
Highest Roll EV
题目详情
Jim 将掷出一个公平的六面骰子,直到获得 。他在这个过程中滚动到的最高数字的预期值是多少?
Jim will roll a fair, six-sided die until he gets a . What is the expected value of the highest number he rolls through this process?
解析
因为 Jim 会在第一次掷出 时停止,所以他在整个过程中掷到的最大值 只可能是 。
:等价于在第一次出现 之前从未掷出 或 。 只看掷骰序列中落在集合 的那些次序(忽略 ),第一次出现的值在 之间对称且等可能,因此
:等价于在第一次出现 之前先出现了 。 只看集合 的首次出现, 与 对称且等可能,所以
:只能是剩余概率
因此
import random
roll_dice = lambda: random.randint(1, 6)
results = []
num_iters = 10_000
for _ in range(num_iters):
highest = 0
while True:
roll = roll_dice()
highest = max(highest, roll)
if roll == 4:
break
results.append(highest)
print(sum(results) / num_iters)Original Explanation
Because Jim stops when he first rolls a , the possible values of the highest roll are , , and . Let be the highest value rolled.
This happens exactly when Jim never rolls a or before the first . Consider only the subsequence of rolls that are in . The first such value is equally likely to be , , or , so
This happens exactly when Jim rolls a before the first . Looking only at the values , the first one to appear is equally likely to be or , hence
This is the remaining probability:
Therefore,
import random
roll_dice = lambda: random.randint(1, 6)
results = []
num_iters = 10_000
for _ in range(num_iters):
highest = 0
while True:
roll = roll_dice()
highest = max(highest, roll)
if roll == 4:
break
results.append(highest)
print(sum(results) / num_iters)