View Single Post
Old 16-08-2009, 09:16   #48
Damien
Remoaner
Cable Forum Team
 
Damien's Avatar
 
Join Date: Mar 2004
Posts: 32,796
Damien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver bling
Damien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver blingDamien has a lot of silver bling
Re: Programming Challenges?

Monty Hall Problem:

Spoiler: 

Code:
 class Program
    {
        const string CAR = "CAR";
        const string GOAT = "GOAT";

        static void Main(string[] args)
        {
            Random random = new Random();
            Double DidntChangeSuccessRate = 0;
            Double DidChangeSuccessRate = 0;
            Int32 doorToOpen;
            IList<String> doors = new List<String>()
            {
                    GOAT, GOAT, GOAT
            };

            for (Int32 round = 1; round <= 10000; round++)
            {

                doors[random.Next(0, 3)] = CAR;
                doorToOpen = random.Next(3); //Choose a Door 
                
                if (round % 2 == 0) //Is Even 
                {
                   doors.Remove(GOAT);
                    if (doors[random.Next(2)] == CAR) //Did they get the car
                        DidChangeSuccessRate++;
                    doors.Add(GOAT);
                }
                else
                {
                    if (doors[doorToOpen] == CAR) //Don't change, did they get the car. 
                        DidntChangeSuccessRate++;
                }
               
                doors[doors.IndexOf(CAR)] = GOAT; //Reset car door to goat. Faster than creating new list class each time
            }

            Console.WriteLine(String.Format("Didn't Change: {0}%", (DidntChangeSuccessRate / 5000) * 100));
            Console.WriteLine(String.Format("Did Change: {0}%", (DidChangeSuccessRate / 5000) * 100));
            Console.ReadKey(true);
        }

    }
Damien is offline   Reply With Quote