function dinner ( )

%*****************************************************************************80
%
%% dinner() simulates the dinner table label problem.
%
%  Discussion:
%
%    N guests sit down at a dinner table, without noticing the name tags.
%    What are the chances that no one sits at their assigned seat?
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    27 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, 'dinner():\n' );
  fprintf ( 1, '  N guests sit down at a dinner table, without noticing the name tags.\n' ) ;
  fprintf ( 1, '  What are the chances that no one sits at their assigned seat?\n' );

  pkzero = zeros ( 1, 20 );
  pkone = zeros ( 1, 20 );
  pkone(1) = 1;
  for n = 2 : 20
    pkzero(n) = ( ( n - 1 ) / n ) * pkone(n-1);
    pkone(n) = pkzero(n-1) / n + ( n - 1 ) * pkone(n-1) / n;
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '  N  P(derangement)\n' );
  fprintf ( 1, '\n' );
  for n = 1 : 20
    fprintf ( 1, '  %2d  %20.16g\n', n, pkzero(n) );
  end

  return
end
