骰子游戏2
Dice Game 2
题目详情
我们玩一个游戏,有两个四面体骰子,红色和蓝色,每个骰子的面都标记为 1-4。在每一回合中,你同时掷两个骰子。
如果蓝色显示的内容多于红色显示的内容,则你将获得差额,否则无需支付任何费用。如果蓝色和红色显示相同的值,则游戏立即结束,否则,你再进行一轮。
游戏的公允价值是多少?
We play a game with two tetrahedral dice, red and blue, each with faces labeled 1-4. In each turn, you simultaneously roll both dice.
If the blue shows more than the red, you are paid the difference, otherwise paid nothing. If the blue and red show the same value, the game is immediately over, otherwise, you take another turn.
What is the fair value of the game?
解析
让我们使用随机方法来解决这个问题。我们将 称为蓝色骰子的结果,将 称为红色骰子的结果。首先,让我们找到 、 和 及其结果,因为它们各自产生不同的结果。
病例总数:
在这些 案例中,有 方法可以创建 等结果。因此,
对于剩余的 案例,一半将导致 ,另一半将导致 。 两种结果的概率均为 因此,
现在让我们根据这三种情况分别找到我们的耳环。我们将 称为我们的收入。
在 的情况下,游戏停止,我们什么也没赚到,所以我们的条件期望是
在 的情况下,我们什么也没赚到,但游戏不会停止,所以 保持不变,因此:
在最后的情况下,,我们得到了差额并且能够继续比赛。在的总共六种情况中,一种将导致的差异,两种将导致的差异,以及三种将导致的差异。平均收集的差异将为 。这将不包括在你的收入中,因此
将所有内容放在一起我们得到: 求解 我们剩下:
import random
roll_dice = lambda: random.randint(1, 4)
earnings = []
num_iters = 10000
for i in range(num_iters):
profit = 0
while(True):
red = roll_dice()
blue = roll_dice()
if blue == red:
break
elif blue > red:
profit += blue - red
elif blue < red:
continue
earnings.append(profit)
print(sum(earnings)/num_iters)Original Explanation
Let's use a stochastic approach to solve this problem. Let's call the outcome of the blue die and the outcome of the red die. First, let's find the , , and and their outcomes, as they each yield a different result.
Total cases:
Of these cases, there are ways to create an outcome such that . Thus,
With the remaining cases, half will result in and the other half will be . Both outcomes have a probability of Thus,
Now let's find our earings given each of these three scenarios. Let's call our earnings.
In the situation , the game stops and we earn nothing so our conditional expectation is
In the situation , we earn nothing but the game doesn't stop so remains unchanged, therefore:
In the final situation where , we are paid the difference and are able to continue playing. Of the six total cases where , one will result in a difference of , two will result in a difference of , and three will result in a difference of . The average collected difference will be . This will be in addition to your earnings so
Putting everything together we get: Solving for we are left with:
import random
roll_dice = lambda: random.randint(1, 4)
earnings = []
num_iters = 10000
for i in range(num_iters):
profit = 0
while(True):
red = roll_dice()
blue = roll_dice()
if blue == red:
break
elif blue > red:
profit += blue - red
elif blue < red:
continue
earnings.append(profit)
print(sum(earnings)/num_iters)