Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #15791

Re: Toughest Game Show Question

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: Toughest Game Show Question
Date 2012-01-12 18:23 -0500
Organization A noiseless patient Spider
Message-ID <4F0F6B6B.4000603@verizon.net> (permalink)
References (1 earlier) <78ecc52b-cc20-477c-9a83-dadd3b46d1ff@u20g2000yqb.googlegroups.com> <20120110171743.392@kylheku.com> <9n5hcpF60bU1@mid.uni-berlin.de> <slrnjgr4oi.2amg.willem@toad.stack.nl> <9n604pFtcjU1@mid.uni-berlin.de>

Show all headers | View raw


On 01/11/2012 12:44 PM, M. Strobel wrote:
> Am 11.01.2012 14:48, schrieb Willem:
>> M. Strobel wrote:
>> ) My simulation shows that by switching your total chance to win
>> ) the car is 1/2 or probability 0.5
>>
>> How did you do the simulation?
>>
>> Here's how I did it:
>>
>> 1 - Randomly pick a door for the car.
>> 2 - Randomly pick a door for the contestant.
>> 3 - Randomly pick one of the remaining two doors for the host.
>> 3a - If that contains a car, pick the other remaining one for the host.
>> 4 - Look at the door that neither the host nor the contestant picked.
>> 5 - Score a win if that door is the door from step 1.
>>
>> And my simulation ends up with 2/3 wins and 1/3 losses.
>>
>>
>> So, could you describe the steps in your simulation?
>>
>>
>> SaSW, Willem
> 
> Well, I do it with minimal abstraction in a list of 2 goats and
> one car.
> 
> 1 generate list by changing one of (goat goat goat) to car
> 2 player randomly picks element
> 2 moderator discloses one goat (not picked)
> 3 player changes / does not change
> 
> this all wrapped up in procedures, accounting only for the results.
> 
> Just can't find any errors there.
> 
> FWIW the code in Tcl is on http://pastebin.com/r6cZBET0
> Oh my god, it is so OT! Let my post die in peace and don't waste your time if you
> don't want to.

Your simulation is needlessly complicated:


#include <limits.h>
#include <stdio.h>
#include <stdlib.h>

static int choose3(void)
{
    int r;
    // max is the largest multiple of 3 that is less than or equal to
    // RAND_MAX+1
    static const int max = 3*((RAND_MAX + 1UL)/3);

    // This removes the bias that would otherwise exist due if
    // max != RAND_MAX+1
    while((r=rand())>= max);

    return r/(max/3);
}

#define TRIAL_RUNS ULONG_MAX
int main(void)
{
    srand(12345);
    unsigned long keep = 0;
    unsigned long change = 0;
    for(unsigned long i=TRIAL_RUNS; i; i--)
    {
        int car = choose3();
        int guess = choose3();
        if(guess == car)// Host chooses one of the other doors.
            keep++;     // Sticking with your original choice wins.
        else            // Host chooses the other door with the goat.
            change++;   // Switching to the remaining door wins.
    }
    printf("%lu runs. Keeping wins %lu=%g%%; switching wins %lu=%g%%\n",
        TRIAL_RUNS, keep, (double)keep/TRIAL_RUNS,
        change, (double)change/TRIAL_RUNS);
    return 0;
}

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Toughest Game Show Question Bill Reid <hormelfree@gmail.com> - 2012-01-10 06:47 -0800
  Re: Toughest Game Show Question tom st denis <tom@iahu.ca> - 2012-01-10 07:11 -0800
    Re: Toughest Game Show Question falk@rahul.net (Edward A. Falk) - 2012-01-11 00:05 +0000
  Re: Toughest Game Show Question Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-01-10 11:23 -0500
  Re: Toughest Game Show Question John Gordon <gordon@panix.com> - 2012-01-10 16:48 +0000
    Re: Toughest Game Show Question Seebs <usenet-nospam@seebs.net> - 2012-01-10 19:15 +0000
      Re: Toughest Game Show Question Keith Thompson <kst-u@mib.org> - 2012-01-10 13:27 -0800
        Re: Toughest Game Show Question James Kuyper <jameskuyper@verizon.net> - 2012-01-10 16:57 -0500
        Re: Toughest Game Show Question Seebs <usenet-nospam@seebs.net> - 2012-01-10 22:39 +0000
  Re: Toughest Game Show Question Stephen Sprunk <stephen@sprunk.org> - 2012-01-10 11:21 -0600
    Re: Toughest Game Show Question Bill Reid <hormelfree@gmail.com> - 2012-01-10 15:43 -0800
      Re: Toughest Game Show Question Stephen Sprunk <stephen@sprunk.org> - 2012-01-10 22:53 -0600
        Re: Toughest Game Show Question Seebs <usenet-nospam@seebs.net> - 2012-01-11 05:00 +0000
          Re: Toughest Game Show Question Kaz Kylheku <kaz@kylheku.com> - 2012-01-11 06:32 +0000
          Re: Toughest Game Show Question James Kuyper <jameskuyper@verizon.net> - 2012-01-11 07:22 -0500
      Re: Toughest Game Show Question falk@rahul.net (Edward A. Falk) - 2012-01-12 22:51 +0000
        Re: Toughest Game Show Question Ian Collins <ian-news@hotmail.com> - 2012-01-13 12:14 +1300
        Re: Toughest Game Show Question ImpalerCore <jadill33@gmail.com> - 2012-01-12 15:17 -0800
  Re: Toughest Game Show Question Shao Miller <sha0.miller@gmail.com> - 2012-01-10 14:33 -0500
  Re: Toughest Game Show Question Kaz Kylheku <kaz@kylheku.com> - 2012-01-11 01:44 +0000
    Re: Toughest Game Show Question Dann Corbit <dcorbit@connx.com> - 2012-01-10 23:48 -0800
      Re: Toughest Game Show Question James Kuyper <jameskuyper@verizon.net> - 2012-01-11 07:23 -0500
    Re: Toughest Game Show Question "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-11 14:33 +0100
      Re: Toughest Game Show Question Willem <willem@toad.stack.nl> - 2012-01-11 13:48 +0000
        Re: Toughest Game Show Question "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-11 18:44 +0100
          Re: Toughest Game Show Question Willem <willem@toad.stack.nl> - 2012-01-11 18:10 +0000
            Re: Toughest Game Show Question "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-11 19:23 +0100
          Re: Toughest Game Show Question James Kuyper <jameskuyper@verizon.net> - 2012-01-12 18:23 -0500
            Re: Toughest Game Show Question "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-01-15 19:03 +0100
            Re: Toughest Game Show Question Willem <willem@toad.stack.nl> - 2012-01-15 19:42 +0000
              Re: Toughest Game Show Question James Kuyper <jameskuyper@verizon.net> - 2012-01-15 16:57 -0500
              Re: Toughest Game Show Question Kaz Kylheku <kaz@kylheku.com> - 2012-01-16 04:16 +0000
                Re: Toughest Game Show Question gazelle@shell.xmission.com (Kenny McCormack) - 2012-01-16 12:14 +0000
                Re: Toughest Game Show Question Bill Reid <hormelfree@gmail.com> - 2012-01-17 07:31 -0800
                Re: Toughest Game Show Question Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-26 09:33 -0800
    Re: Toughest Game Show Question "BartC" <bc@freeuk.com> - 2012-01-12 21:07 +0000
      factor jgk@panix.com (Joe keane) - 2012-01-12 22:53 +0000
      Re: Toughest Game Show Question pete <pfiland@mindspring.com> - 2012-01-14 23:38 -0500

csiph-web