Code Monkey home page Code Monkey logo

monty-hall-proof's Introduction

Monty-Hall-Proof

import random

n = 100000 # number of times to run the estimation

woncar = 0

for i in range(n):
    doors = [1,2,3]
    car = random.randint(1,3)
    choice = random.randint(1,3)

    doors.remove(car) # remove for now to choose which one reveal
    if(choice in doors):
        doors.remove(choice) # dont reveal the choice
    reveal = random.sample(doors,1)[0]

    '''
        Here is where you find the proof...
        In the following we check if our other option which is != choice is the same as car. 
        Since the other non car options has been removed we only need to check if choice!=car
        You can notice that we dont need lines 12-15 
        This is too obvious that the chance is 66% not 50%.
    '''
    if(choice != car):
        woncar += 1
    
    print("Chance that you win a car if you switch:", woncar/(i+1))

monty-hall-proof's People

Contributors

naklecha avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.