Some simulation code from sci.math.num-analysis

julian@axcn01.cern.ch (Julian James Bunn):

I stand corrected, having now simulated the damn thing ... the results from the simulation (program enclosed) being:

Number of games       100000
No change wins         33324   33.32400
Swap wins              66676   66.67600

I still find it preposterous, and am quite flabbergasted. Thanks to everyone who has tried to explain it to me ...

Julian

      Program ThreeDoor
      integer seed /9876/
      integer taken(3)
      real v
c
      v = ran(seed) ! initialise prng
      ngames = 0        ! counts the total games
      n_no_change = 0   ! counts the number of wins with no change
      n_change = 0      ! counts the number of wins when swapping doors
      do 1 igame = 1,100000
         v = ran(seed)
c
c Define the door behind which the prize is concealed
c
         if(v.lt.0.333333) then
            iprize = 1
         else if(v.ge.0.666666) then
            iprize = 3
         else 
            iprize = 2
         endif
c
c Randomise the guest's selection
c
         v = ran(seed)
         if(v.lt.0.333333) then
            iselect = 1
         else if(v.gt.0.666666) then
            iselect = 3
         else
            iselect = 2
         endif
c
c Count for no change strategy
c
         ngames = ngames + 1
         if(iselect.eq.iprize) n_no_change = n_no_change + 1
c
c Find which door the host opens ...
c
         do j=1,3
            taken(j) = 0
         end do
         taken(iselect) = 1
         taken(iprize) = 1
         do j=1,3
            if(taken(j).eq.0) iopen = j
         end do
c
c and thus which the guest swaps to ...
c
         do j=1,3
            if(j.ne.iopen.and.j.ne.iselect) iswap = j
         end do
c
c Count for swap strategy
c
         if(iswap.eq.iprize) n_change = n_change + 1
    1 continue
c
      write(6,*) 'Number of games ',ngames
      write(6,*) 'No change wins  ',n_no_change,100.*n_no_change/ngames
      write(6,*) 'Swap wins       ',n_change,100.*n_change/ngames
      end