function missing ( trial_num, A, M )

%*****************************************************************************80
%
%% missing() simulates the missing senator problem.
%
%  Discussion:
%
%    There are 100 senators.
%    A bill needs a majority of present senators to pass.
%    A senators are against the bill.
%    M senators are missing the vote.
%    What is the probability that the bill will be defeated?
%
%  Example:
%
%    A = 49, M = 3, p = 0.12878787
%    A = 49, M = 4, p = 0.06373
%    A = 49, M = 5, p = 0.193845
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    24 January 2018
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Digital Dice: Computational Solutions to Practical Probability Problems,
%    Princeton, 2008,
%    ISBN: 978-0-691-15821-1.
%
%  Input:
%
%    integer trial_num: the number of trials.
%
%    integer A, M, the number of senators against the bill, and the
%    number who are missing.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'missing():\n' );
  fprintf ( 1, '  There are 100 senators.\n' );
  fprintf ( 1, '  A bill needs a majority of present senators to pass.\n' );
  fprintf ( 1, '  A senators are against the bill.\n' );
  fprintf ( 1, '  M senators are missing the vote.\n' );
  fprintf ( 1, '  What is the probability that the bill will be defeated?\n' );

  defeats = 0;
  for loop = 1 : trial_num
    votes = zeros ( 1, 100 );
    for k = 1 : A
      votes(k) = -1;
    end
    for k = A + 1 : 100
      votes(k) = 1;
    end

    for k = 1 : M
      go = 1;
      while ( go == 1 )
        j = floor ( 100 * rand ( ) + 1 );
        if ( votes(j) ~= 0 )
          votes(j) = 0;
          go = 0;
        end
      end
    end

   vote = sum ( votes );
   if ( vote < 0 )
      defeats = defeats + 1;
    end

  end

  defeats = defeats / trial_num;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Probability of defeat = %g\n', defeats );

  return
end
