function floss ( n )

%*****************************************************************************80
%
%% floss() considers the dental floss problem.
%
%  Discussion:
%
%    A person buys two rolls of dental floss.
%    Each roll supplies N feet of floss.
%    The person randomly selects a roll and takes 1 foot of floss.
%    When one roll runs out, how many feet remain in the other roll?
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    07 May 2019
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Digital Dice: Computational Solutions to Practical Probability Problems,
%    Princeton, 2008,
%    ISBN: 978-0-691-15821-1.
%
%  Input:
%
%    integer N, the number of feet of floss in a full roll.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'floss():\n' );
  fprintf ( 1, '  A person buys two rolls of dental floss.\n' );
  fprintf ( 1, '  Each roll has %d feet of floss.\n', n );
  fprintf ( 1, '  The person randomly selects a roll and takes 1 foot of floss.\n' );
  fprintf ( 1, '  When one roll runs out, how many feet remain in the other roll?\n' );
%
%  MATLAB will issue many warnings about NCHOOSEK() not being exact unless
%  we issue this command to suppress warnings.
%
  warning ( 'off' )

  sum = 0;
  for k = 1 : n
    sum = sum + ( k * nchoosek ( 2 * n - k - 1, n - k ) / ( 2 ^ ( 2 * n - k - 1 )));
  end

  warning ( 'on' )

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Average remaining floss = %g\n', sum );
 
  return
end
