【Puzzle】祝你好运

  |  

摘要: 《概率50题》祝你好运

【对算法,数学,计算机感兴趣的同学,欢迎关注我哈,阅读更多原创文章】
我的网站:潮汐朝夕的生活实验室
我的公众号:算法题刷刷
我的知乎:潮汐朝夕
我的github:FennelDumplings
我的leetcode:FennelDumplings


参考: 《Fifty challenging problems in probability with solutions》


问题描述

Chuck-a-luck

Chuck-a-luck is a gambling game often played at carnivals and gambling houses
A player may bet on any one of the numbers 1, 2, 3, 4, 5, 6

Three dice are rolled

If the player’s number appears on one, two, or three of the dice, he receives respectively one, two, or three times his original stake plus his own money back
Otherwise, he loses his stake

What is the player’s expected loss per unit stake?

“祝你好运”一种赌博游戏,经常在嘉年华和赌场玩。

玩家可以在 1, 2, 3, 4, 5, 6 中的某个数上下注。然后投掷 3 个骰子。

如果玩家下注的数字在这三次投掷中出现了 x 次,则玩家获得 x 倍原始投注资金,并且原始投注资金也会返还,也就是总共拿回 (x + 1) 倍原始投注资金。如果下注的数字没有出现,则原始投注资金不会返还。

问:每单位原始投注资金,玩家期望会输多少。

思路参考

设原始投注资金为 s,下注的数字在三次投掷中出现了 x 次,x 的取值为 0, 1, 2, 3,下面我们分别考虑这四种情况。

按照期望的定义

拿回的钱的期望为

每单位投注资金的损失为 17/216 = 0.0787

蒙特卡洛模拟

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import numpy as np

def game():
x = 0
for _ in range(3):
if np.random.randint(1, 7) == 1:
x += 1
if x == 0:
return 0
return x + 1

def test():
T = int(1e6)
total_income = 0
for t in range(T):
total_income += game()
print("expected loss: {:.6f}".format((T - total_income) / T))

for i in range(10):
test()

模拟结果

1
2
3
4
5
6
7
8
9
10
expected loss: 0.078817
expected loss: 0.078182
expected loss: 0.078731
expected loss: 0.078875
expected loss: 0.078526
expected loss: 0.078657
expected loss: 0.078634
expected loss: 0.079033
expected loss: 0.079353
expected loss: 0.079307

Share