首页 > 其他分享 >Monty Hall problem

Monty Hall problem

时间:2024-08-07 13:05:19浏览次数:4  
标签:door prize Player Hall choice player problem options Monty

The problem can be formulated as follows. As a participant of a game show, you have to choose one of three doors. Behind one of the doors is a prize, behind two other doors is nothing. After you pick a door, the game host, who knows where the prize is, selects a door with no prize from the two remaining doors, and opens it. Then the host tells you that you may stick to your original choice or switch to another closed door. Should you do it?

 

Player A would always stick to the original choice, while Player B would always switch the door. 

 

from random import choice


N = 100000

player_a_win = 0  # Palyer A sticks to the original choice.
player_b_win = 0  # Palyer B switches the door.


def monty_choice(prize, options):
    if prize[options[0]] == False and prize[options[1]] == False:
        return choice(options)

    return options[0] if prize[options[1]] == True else options[1]


for _ in range(N):
    prize = [False, False, False]
    prize[choice([0, 1, 2])] = True

    options = [0, 1, 2]
    player_choice = choice(options)
    options.remove(player_choice)
    options.remove(monty_choice(prize, options))

    if prize[player_choice]:
        player_a_win += 1
    if prize[options[0]]:
        player_b_win += 1


print(f"Player A: {player_a_win / N}")
print(f"Player B: {player_b_win / N}")

 

Player A: 0.33323
Player B: 0.66677

 

Player B, who always switches doors, wins twice more often! 

If your intuition still rebels, here is an easy way to think about this game. Suppose you have initially chosen a door with the prize. The chances of this lucky event are 1 out of 3. In this case, switching doors means failure: you move away from your prize. However, in any other case (2 out of 3) you choose between your empty door and another closed door with the prize behind. Therefore, “always switch” strategy wins in 2/3 of all the games.

 

标签:door,prize,Player,Hall,choice,player,problem,options,Monty
From: https://www.cnblogs.com/zhangzhihui/p/18346838

相关文章

  • ARC181 - B - Annoying String Problem
    B-令人讨厌的字符串问题编辑:evima在大多数情况下,\(f(S,T,X)\)和\(f(S,T,Y)\)的长度相等,这揭示了\(T\)的长度。让我们来看看当已知\(S\)和\(T\)的长度时,在什么条件下\(S\)和\(T\)满足\(f(S,T,X)=f(S,T,Y)\)。例题例如,当\(|S|=6\)和\(|T|=4\)时,让我们考虑当\(S+......
  • 洛谷P1001 A+B Problem的一些歪解(淼作)
    一、LCT#include<iostream>#include<cstring>#include<cstdio>#include<cstring>usingnamespacestd;structnode{intdata,rev,sum;node*son[2],*pre;booljudge();boolisroot();voidpushdown();voidupda......
  • 【简单菊花图】Codeforce 1583Problem - B.md
    1583Problem-B-Codeforces题目大意:n个点的无根树给出m个限制条件(a,c,b)在a到b路径上不能存在c点,求任意一种可能的树的所有边注意数据范围:1<m<n<1e5这说明了最多有n-1个限制条件这说明至少有一个点不存在限制条件即这个点可以作为根节点root连接其他所有点形成边......
  • Floyd-Warshall
    Floyd-WarshallFloyd-Warshall算法的核心思想是利用动态规划的思想,通过逐步更新距离矩阵来求解所有节点对之间的最短路径。它适用于解决图中节点对数量较小且权重可以为负的情况。时间复杂度为O(n^3)。java代码模板staticfinalintINF=Integer.MAX_VALUE;//graph中......
  • CodeForces 1619D New Year's Problem
    题目链接:CodeForces1619D【NewYear'sProblem】思路    可以因为最多只能逛n-1个商店,当n-1大于等于m的时候,所有朋友都能取最大值,否则至少有两个人要选择相同的商店,所以依次枚举两个人选择同一个商店,其他人选择喜悦值最大的商店。代码#include<cstddef>#incl......
  • [USACO1.5] 八皇后 Checker Challenge 题解
    [USACO1.5]八皇后CheckerChallenge题目描述一个如下的\(6\times6\)的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行、每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子。上面的布局可以用序列\(2\4\6\1\3\5\)来描述,第\(i\)个数字表示在......
  • hall 定理学习笔记
    万恶之源基本定义完美匹配是指最大匹配数为min(|X|,|Y|)也就是X或Y集合其中一个集合所有点都被匹配了。定理内容我们来假设X集合点少一点好了。X集合就当做有n个点。那么二分图G存在完美匹配,则取任意正整数1<=k<=n,均满足我从X集合选出k个不同的点,那么它们连向的y集合的点个......
  • PostgreSQL安装异常:Problem running post-install step
    1.错误详情安装PostgreSQL时快要完成的时候抛出异常Problemrunningpost-installstep.Installationmaynotcompletecorrectlty.Thedatabaseclusterinitialisationfailed.2.解决方法以管理员权限打开PowerShell找到PostgreSQL安装目录,进入bin文件夹(例子中是D:\Post......
  • Yet Another Problem
    遇到连续段的异或和,考虑前缀异或和对区间\([l,r]\),观察实施一次操作\([L,R]\)后,区间会变成什么样。不难发现,\([L,R]\)的异或前缀和会变成\([sum_R,sum_{L-1},sum_R,...,sum_{L-1},sum_R]\),于是可以知道,如果\(sum_R≠sum_{L-1}\),就无解;如果\([l,r]\)的长度为奇数,操作一次整个区间......
  • problems笔记(^^)
    一些遇到的问题及其践而有效的解决方案CSND博客无法访问  解决方案 若是还无法访问......