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);
}
}
}