function committee ( trial_num )

%*****************************************************************************80
%
%% committee() simulates the committee problem.
%
%  Discussion:
%
%    From a faculty of 6 professors, 6 associate professors, 10
%    assistant professors, and 12 instructors, a committee of size 6
%    is formed randomly.  What is the probablity that there is at least
%    one person of each rank in the committee?
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    28 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.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'committee():\n' );
  fprintf ( 1, '  From a faculty of 6 professors, 6 associate professors, 10\n' );
  fprintf ( 1, '  assistant professors, and 12 instructors, a committee of size 6\n' );
  fprintf ( 1, '  is formed randomly.  What is the probablity that there is at least\n' );
  fprintf ( 1, '  one person of each rank in the committee?\n' );

  structure = 0;

  for loop = 1 : trial_num

    count = 0;

    mix = randperm ( 34 );
    for i = 1 : 6
      select(i) = mix(i);
    end

    rank = ones(1,4);

    for i = 1 : 6
      if ( select(i) < 7 )
        count = count + rank(1);
        rank(1) = 0;
      elseif ( 7 <= select(i) & select(i) < 13 )
        count = count + rank(2);
        rank(2) = 0;
      elseif ( 13 <= select(i) & select(i) < 23 )
        count = count + rank(3);
        rank(3) = 0;
      else
        count = count + rank(4);
        rank(4) = 0;
      end
    end

    if ( count == 4 )
      structure = structure + 1;
    end

  end

  structure = structure / trial_num;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Estimated probability = %g\n', structure );
  fprintf ( 1, '  Exact probablity      = %g\n', 1 - 835144/1344904 );

  return
end
