function jury ( )

%*****************************************************************************80
%
%% JURY estimates the probability that an appeals court makes a mistake.
%
%  Discussion:
%
%    There are 5 judges on an appeals court.
%    Each judge has a probability of making a correct ruling.
%    What is the probability that a majority of the judges will rule incorrectly?
%
%    Variation: suppose the worst judge (#5) always simply agrees with the
%    best judge (#1).  How does this change the probability?
%
%  Example:
%
%    With the given data, the probability of a mistaken judgement should
%    be about 0.0070419.
%
%  Modified:
%
%    26 January 2018
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Digital Dice: Computational Solutions to Practical Probability Problems,
%    Princeton, 2008,
%    ISBN: 978-0-691-15821-1.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'JURY:\n' );
  fprintf ( 1, '  There are 5 judges on an appeals court.\n' );
  fprintf ( 1, '  Each judge has a probability of making a correct ruling.\n' );
  fprintf ( 1, '  What is the probability that a majority of the judges will rule incorrectly?\n' );

  p = [ 0.95, 0.95, 0.90, 0.90, 0.80 ];

  mistakes = 0;

  for loop = 1 : 10000000

    votes = zeros ( 1, 5 );
    for k = 1 : 5
      if ( rand ( ) > p(k) )
        votes(k) = 1;
      end
    end

    result = sum ( votes );
    if ( result > 2 )
      majority = 1;
    else
      majority = 0;
    end

    mistakes = mistakes + majority;

  end

  mistakes = mistakes / 10000000;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Probability of a mistaken judgement = %g\n', mistakes );

  return
end
