Jump to content
  • Advertisement
Sign in to follow this  
Icebone1000

Monty Hall Problem Code to Proof

This topic is 508 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Theres something wrong here..

 

https://en.wikipedia.org/wiki/Monty_Hall_problem

 

 

First...Thats gotta be bullshit, 50% chances are always 50% chances, u dont dare stack chances man u_u**, what dimension is this?? I dont get it..

 

So I went and coded it, but its not even just getting me better chances, its getting me ~60% wins if I change the door, and ~30% wins if I keep the door? Then I went and added a pick one of two chances with the same code structure to check if Im not doing some retarded stuff, but then I do get an average of ~50% wins..

 

It gotta be something related to random numbers not being true random or something...Can someone spot issues? I need issues to keep going with my life, that doesnt make any sense

using System;

public class Test
{
    enum prize{ goat, car};

	Random rnd = new Random();//Environment.TickCount);
	Random rndPick = new Random(Environment.TickCount); // just trying to see if makes a difference
    
    void Shuffle(ref prize[] array){
        
        //Console.WriteLine("shuffling");
		int n = array.Length;
		prize[] doors = new prize[n];

		for (int it = 0, nElementsRemaining = n; it < n; ++it)
		{ 
           // Console.WriteLine("it = "+it);
            
            int randomIndex = rnd.Next(0, nElementsRemaining);
            //Console.WriteLine("randomIndex = "+randomIndex);
            doors[it] = array[randomIndex];
            
            array[randomIndex] = array[--nElementsRemaining];
             //Console.WriteLine("nElementsRemaining = "+nElementsRemaining);
             
            // string szarray =
            //array[0].ToString() + " " + array[1].ToString() + " " + array[2].ToString();
            //Console.WriteLine("a = "+szarray);
        }
        
        array = doors;
        //Console.WriteLine("--------");
    }


	public void Execute(bool changeDoor, int tries){

		int currTries = tries;//5000000;
        int wins = 0;
        int loses = 0;

		while (--currTries >= 0)
		{ 
        
           // Console.WriteLine("==================================");
        
            prize[] doors = new prize[]{prize.goat, prize.goat, prize.car};
            Shuffle(ref doors);
            
           // string szDoors =
           // doors[0].ToString() + " " + doors[1].ToString() + " " + doors[2].ToString();
            //Console.WriteLine("szDoors = "+szDoors);



			int pickDoor = rndPick.Next(0, 3);
           // Console.WriteLine("pickDoor = "+pickDoor + "\n=============================");
            int eliminatedDoor = 0;
            while(true){
                
                if( eliminatedDoor  != pickDoor && doors[eliminatedDoor ] == prize.goat ) break;
                ++eliminatedDoor; 
            }
           // Console.WriteLine("eliminatedDoor = "+eliminatedDoor);
			if (changeDoor == true)
			{
            
                bool[] doorsRemaining = new bool[] {true, true, true};
                doorsRemaining[pickDoor] = false;
                doorsRemaining[eliminatedDoor] = false;
                
                pickDoor = 0;
                while(true){
                    
                    if( doorsRemaining[pickDoor] == true ) break;
                    pickDoor++;
                }
            }
            
            if( doors[pickDoor] == prize.car ) wins++;
            else loses++;
	    }
	    
	    Console.WriteLine("wins:  " + wins + "\n" + "loses: "+ loses);
		float avgWins = (float)wins / (float)tries;
		Console.WriteLine("avg:  " + avgWins.ToString("0.0###"));
	}

	public void ExecutePicOfTwo(int tries)
	{
		int currTries = tries;//5000000;
        int wins = 0;
		int loses = 0;

		while (--currTries >= 0)
		{
			prize[] doors = new prize[] { prize.goat, prize.car };
			Shuffle(ref doors);

			int pickDoor = rndPick.Next(0, 2);

			if (doors[pickDoor] == prize.car) wins++;
			else loses++;	
		}

		Console.WriteLine("wins:  " + wins + "\n" + "loses: " + loses);
		float avgWins = (float)wins / (float)tries;
		Console.WriteLine("avg:  " + avgWins.ToString("0.0###"));
	}

	public static void Main()
	{
		Console.WriteLine("Press enter to step.");
		while (true)
		{
			int tries = 50000;

			Console.ReadLine();
			Test newTest = new Test();
			Console.WriteLine("pic of two:");
			newTest.ExecutePicOfTwo(tries);

			Console.ReadLine();
			//Test newTest = new Test();
			Console.WriteLine("keep door:");
			newTest.Execute(false, tries);

			Console.ReadLine();
			Console.WriteLine("change door:");
			newTest.Execute(true, tries);
		}
	}
		
}

Share this post


Link to post
Share on other sites
Advertisement

You know that one cassino example:

 

You keeping betting low values on a color. Till you get some high sequence of the same colors.

black, red, black, black, black, black

Now, chances are the next one will be red, so you bet everything...and ure screwed cause 50% chances is always 50% chances..

Statistically speaking, that means that using this technique you could increase ur money (cause for a fixed number of tries, u know the average number that each color will be pick)..but does this work in practice like the Monty Hail case? No..I guess...I dunno anymore..I mean, if this works everyone would do it..but I dunno how cassinos work.

 

I though this one was the same case.

 

But them every time I run the code, its always the same %, not a single time I manage to get lower then 50% wins, even with 10 tries you have super high win score, with 50 tries its already dead win

Share this post


Link to post
Share on other sites

I need issues to keep going with my life, that doesnt make any sense
Sorry for your life, but our intuition and expectations with chances is just broken.

 

I learned a long time ago to trust a computed stochastic result more than my own guts, so for anything with chances, I convert to a stochastic problem, and do the computations (or a simulation like you do). That's the real answer, no matter what my instinct tells me.

 

The missing thing that explains the stochastic result often comes much later for me. I figured this one out  as well, and in this case it is as Lactose said. The show host brings in new information, which changes the odds. If you stay with your old choice, you're not using that new information. If you switch, you do, and the chances shift in your favor.

Share this post


Link to post
Share on other sites

You know that one cassino example:
 
You keeping betting low values on a color. Till you get some high sequence of the same colors.
black, red, black, black, black, black
Now, chances are the next one will be red, so you bet everything...and ure screwed cause 50% chances is always 50% chances..
Statistically speaking, that means that using this technique you could increase ur money (cause for a fixed number of tries, u know the average number that each color will be pick)..but does this work in practice like the Monty Hail case? No..I guess...I dunno anymore..I mean, if this works everyone would do it..but I dunno how cassinos work.


If you're talking about roulette, players with "infinite money" still statistically lose in the long run due to the 0 and 00 "house numbers" on the wheel. The payouts on all other options do not factor in those slots, but the odds of landing on a particular slot still do, so the payout/odds ratios are always less than break-even for the player.

https://en.wikipedia.org/wiki/Roulette#Bet_odds_table Edited by Nypyren

Share this post


Link to post
Share on other sites
Now, chances are the next one will be red, so you bet everything...and ure screwed cause 50% chances is always 50% chances..

 

Yes, and how does that compare to the monty hall problem? Montey Hall isn't 50/50. I mean its pretty obvious that you didn't properly read the article nor watched the video (which explains that its exactly 33/66 as I've watched it to confirm I'm correct). But at least now with the answers you should be able to understand that, which you don't seem to do. Jep, 50/50 is always 50/50, but when its not 50/50 it is not 50/50... like rolling a dice, you cannot say "well its always 50/50 if I roll a 1 or not", which is essentially what this boils down to when applied to the monty hall problem (only that this problem is a tad bit more confusing than a dice, to be fair) :D

Edited by Juliean

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!