PROGRAM  MONTY_HALL_PROBLEM;

{The Monty Hall Problem (Ziegenproblem) gets its name from the TV game show, Lets Make A Deal, hosted by Monty Hall1. The scenario is such: you are given the opportunity to select one closed door of three, behind one of which there is a prize. The other two doors hide goats (or some other such nonprize), or nothing at all. Once you have made your selection, Monty Hall will open one of the remaining doors, revealing that it does not contain the prize2. He then asks you if you would like to switch your selection to the other unopened door, or stay with your original choice. Here is the problem: Does it matter if you switch the door? The impressive answer ist Yes, in 2/3 of cases you are getting better to switch}
//Uses crt; loc's=60

var  i,n,j,m, cr,cw: Integer;
     house,first,moderator,change: Integer;
     reInput: string;              {of yes and now}

FUNCTION myRandom: Integer;
Begin
  result:= Random(3) + 1;          {three doors}
End;

PROCEDURE Input (Var zahl1,zahl2: Integer);
 Begin
   Writeln('');
   zahl1:= strtoint(readln('How many shows do you want?:'));
   zahl2:= strtoint(readln('How many runs, significant is about 900'))
 End;

PROCEDURE Print;
 Begin
   Writeln('  the change was successfull in  ' + inttostr(cr) +'  runs');
   Writeln('              but no success in  ' + inttostr(cw) +'  runs')
 End;

PROCEDURE Show;
 Begin
   Randomize;
   house:= myRandom; {the winning}
   first:= myRandom; {first guess}
   Repeat
     moderator:= myRandom;
   Until (moderator<>house) And (moderator<>first);
    //1+2+3 are 6 so we can find only one change!
   change:= 6 - moderator - first;
   If change = house
     Then inc(cr)
     Else inc(cw);
 End;

BEGIN   {main}
//Clrscr;
  Repeat;
    n:= 0; {shows}
    m:= 0; {runs}
    Input(n,m);
    For i:= 0 to n-1 do begin
      cr:= 0;
      cw:= 0;
      For j:= 1 to m do
        Show;
      Print    
    End;         {for i}
    Writeln('');
    Writeln('  new simulation?  (y/n) ');
    reInput:= Readln('  new simulation?  (y/n) ');
  Until(reInput= 'n') Or (reInput= 'N')
END.