Created
February 27, 2022 10:11
-
-
Save yves-chevallier/0b79f8e60d6b8b09ce550898afd450e3 to your computer and use it in GitHub Desktop.
Monty Hall Problem - The Game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Monty Hall Problem - The Game | |
https://fr.wikipedia.org/wiki/Probl%C3%A8me_de_Monty_Hall | |
Supposez que vous êtes sur le plateau d'un jeu télévisé, face à trois portes | |
et que vous devez choisir d'en ouvrir une seule, en sachant que derrière l'une | |
d'elles se trouve une voiture et derrière les deux autres des chèvres. | |
Vous choisissez une porte, disons la numéro 1, et le présentateur, qui sait, | |
lui, ce qu'il y a derrière chaque porte, ouvre une autre porte, disons la numéro 3, | |
porte qui une fois ouverte découvre une chèvre. | |
Il vous demande alors : « désirez-vous ouvrir la porte numéro 2 ? ». | |
Avez-vous intérêt à changer votre choix ? » | |
""" | |
import random | |
import numpy as np | |
N = 100 | |
data = [np.random.permutation(["Goat", "Goat", "Car"]) for i in range(N)] | |
def play(data, switch=False): | |
# Player choose a box | |
choice = np.random.randint(len(data)) | |
if not switch: | |
return data[choice] | |
# Player choose a box | |
data = np.delete(data, choice) | |
# The presenter removes a box were there is no cars | |
data = np.delete(data, np.where(data == "Goat")[0][0]) | |
# Eventually the last remaining box is the choosen one | |
return data[0] | |
print(f"Doesn't change : {[play(d) for d in data].count('Car') / N * 100}%") | |
print(f"Does change : {[play(d, True) for d in data].count('Car') / N * 100}%") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment