Created
August 29, 2018 18:39
-
-
Save ettoreleandrotognoli/ad24cab693d94c42bf44d193adbd85dd to your computer and use it in GitHub Desktop.
Problema de Monty Hall
This file contains 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
import random | |
def gerar_portas(): | |
porta = random.choice(list(range(3))) | |
portas = [False] * 3 | |
portas[porta] = True | |
return portas | |
def escolher_porta(portas,evitar=None): | |
possiveis = list(filter(lambda i_p : i_p[1] is not None and i_p[0] != evitar,enumerate(portas))) | |
return random.choice(possiveis)[0] | |
def abrir_porta(portas, escolhida): | |
possiveis = list(filter(lambda i_p : i_p[1] == False and i_p[0] != escolhida,enumerate(portas))) | |
return random.choice(possiveis)[0] | |
acertos = 0 | |
erros = 0 | |
for i in range(1000): | |
portas = gerar_portas() | |
acho_que_eh = escolher_porta(portas) | |
para_abrir = abrir_porta(portas,acho_que_eh) | |
portas[para_abrir] = None | |
acertou = portas[acho_que_eh] | |
if acertou: | |
acertos += 1 | |
else: | |
erros += 1 | |
print('burro') | |
print('acertos',acertos) | |
print('errros',erros) | |
acertos = 0 | |
erros = 0 | |
for i in range(1000): | |
portas = gerar_portas() | |
acho_que_eh = escolher_porta(portas) | |
para_abrir = abrir_porta(portas,acho_que_eh) | |
portas[para_abrir] = None | |
acho_que_eh = escolher_porta(portas,acho_que_eh) | |
acertou = portas[acho_que_eh] | |
if acertou: | |
acertos += 1 | |
else: | |
erros += 1 | |
print('leo') | |
print('acertos',acertos) | |
print('errros',erros) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment