function monty ( )

%*****************************************************************************80
%
%% MONTY simulates the Let's Make a Deal puzzle.
%
%  Discussion:
%
%    There are three doors.
%    A prize is behind one of the doors.
%    You name a door.
%    The host then opens one of the other doors, which is guaranteed not to
%    conceal a prize.
%    You may now choose to switch your choice to the remaining door, or not.
%    What is the better strategy?
%
%  Modified:
%
%    29 January 2018
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Dueling Idiots and Other Probability Puzzlers,
%    Princeton, 2012,
%    ISBN: 978-0691155005.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'MONTY:\n' );
  fprintf ( 1, '  There are three doors.\n' );
  fprintf ( 1, '  A prize is behind one of the doors.\n' );
  fprintf ( 1, '  You name a door.\n' );
  fprintf ( 1, '  The host then opens one of the other doors, which is guaranteed not to\n' );
  fprintf ( 1, '  conceal a prize.\n' );
  fprintf ( 1, '  You may now choose to switch your choice to the remaining door, or not.\n' );
  fprintf ( 1, '  What is the better strategy?\n' );

  WNS = 0;
  WWS = 0;
  switch1 = 1 / 3;
  switch2 = 2 / 3;

  for game = 1 : 10000
%
%  Place the prize.
%
    choice = rand ( );

    if ( choice <= switch1 )
      prize = 1;
    elseif ( choice <= switch2 )
      prize = 2;
    else
      prize = 3;
    end
%
%  Pick a door.
%
    choice = rand ( );
    if ( choice <= switch1 )
      select = 1;
    elseif ( choice <= switch2 )
      select = 2;
    else
      select = 3;
    end
%
%  If prize is behind your selected door, win if you don't switch.
%  If prize is not behind your selected door, win if you do switch.
%
    if ( select == prize )
      WNS = WNS + 1;
    else
      WWS = WWS + 1;
    end

  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of trials is 10,000\n' );
  fprintf ( 1, '  No-switch strategy wins %d times\n', WNS );
  fprintf ( 1, '  Switch strategy wins    %d times\n', WWS );

  return
end
