<jupyter_start><jupyter_text>Modeling The Monty Hall Problem    Problem definitions   Suppose you're on a game show, and you're given the choice of three doors:      Behind one door is a car and behind the others, goats.       You pick a door, say No. 1, and the host, who knows what's behind the doors,      opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?"       Is it to your advantage to switch your choice?                       Wining Strategy       Always change your choice of door because:        * Sticking with your original door: you will only win one out of every three times you play        the game           * Change your selection: you will win two out of every three times you play.          Seems very not intuitive!!!     Few Intuitive aids (link) :        *  think the really crucial thing that people overlook is not their first choice,        but the host's choice, and the assumption that the host made sure not to         reveal the car.It is to your advantage to switch if the host is making sure         only to reveal a goat. On the other hand, if the host picked randomly between        doors 2 and 3, and happened to reveal a goat, then there is no advantage to switching.     * Change the problem to 100 door close .   Pythonic 'Proof'  based mostly on link<jupyter_code>import random 


 
class MontyHall(object):
    def __init__(self,switch_strategy=True):
        self.switch_strategy = switch_strategy        

    def pick_door(self):
        return random.randint(1,3)
 
    def run_game(self):
        prize_door = pick_door()        
        participent_door = pick_door()
        
        # host valid door one of the doors participant didnt pick . all the doors together sumed to 6 
        # so we substract the two door we dont want and pick one of the options
        host_door = pick_door()
        host_door = random.choice([6 - participent_door - prize_door,
                                   6 - participent_door - host_door])
        
        if self.switch_strategy:
            # all the doors together sumed to 6 so to get the new door we need to subscract both
            # our first pick and the host pick             
            participent_door = 6 - participent_door - host_door
    
        return participent_door == prize_door
 

class simulation(object):
    
    def __init__(self,switch_strategy=True, iterations=10000):
        self.iterations = iterations
        self.switch_strategy = switch_strategy
        self.m = MontyHall(switch_strategy)
        self.perc_win = 0
        
    def run_simulation(self):
        # self.m.run_game() return indicator if player one win or not
        # since bool are ints we can sum the result for total # of wins         
        wins = sum(self.m.run_game()
                   for i in range(self.iterations))
        losses = self.iterations-wins
        self.perc_win = 100.0*wins / (wins+losses)
        return self  
    
    def show_stats(self):
        print("Monty Hall simulation with{} switching with {} iterations".format('' if self.switch_strategy else 'out',
                                                                                 self.iterations))
        print("\tprecentage of winning is: {}% \n"
              "\tprecentage of lossing is: {}%\n".format(self.perc_win,
                                                        100-self.perc_win))
 

simulation(switch_strategy=True).run_simulation().show_stats()
simulation(switch_strategy=False).run_simulation().show_stats()<jupyter_output>Monty Hall simulation with switching with 10000 iterations
	precentage of winning is: 66.89% 
	precentage of lossing is: 33.11%

Monty Hall simulation without switching with 10000 iterations
	precentage of winning is: 33.1% 
	precentage of lossing is: 66.9%
{'fraction_non_alphanumeric': 0.061245764920510815, 'fraction_numerical': 0.013552254365389628, 'mean_word_length': 2.2144053601340032, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '252766', 'license': 'MIT', 'n_tokens_mistral': 1064, 'n_tokens_neox': 989, 'n_words': 421, 'path': 'stale/Monty Hall Problem.ipynb', 'repo_name': 'eyaltrabelsi/Monty-Hall-Problem', 'size': '3837'}