function esim ( N )

%*****************************************************************************80
%
%% ESIM estimates E by a binning process.
%
%  Discussion:
%
%    Sample N points in the unit interval.
%    Put them into N bins of equal width.
%    Let Z be the number of empty bins.
%    N/Z is an estimate of E. 
%
%  Modified:
%
%    29 January 2018
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Dueling Idiots and Other Probability Puzzlers,
%    Princeton, 2012,
%    ISBN: 978-0691155005.
%
%  Parameters:
%
%    Input, integer N, the number of random values.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'ESIM:\n' );
  fprintf ( 1, '  Sample N points in the unit interval.\n' );
  fprintf ( 1, '  Put them into N bins of equal width.\n' );
  fprintf ( 1, '  Let Z be the number of empty bins.\n' );
  fprintf ( 1, '  N/Z is an estimate of E. \n' );

  bin = zeros(1,N);
  for j = 1 : N
    number = floor ( N * rand ( ) ) + 1;
    bin(number) = bin(number) + 1;
  end

  empty = 0;
  for j = 1 : N
    if ( bin(j) == 0 )
      empty = empty + 1;
    end
  end

  e_estimate = N / empty;
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Estimate for E = %g\n', e_estimate );
  fprintf ( 1, '  Exact value =    %g\n', exp ( 1 ) );

  return
end

