function snakes_histogram ( n )

%*****************************************************************************80
%
%% snakes_histogram() makes a game-length histogram for Snakes and Ladders.
%
%  Discussion:
%
%    For histograms, we plot the raw data, whereas for bar charts, we
%    plot the tallies.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    17 July 2017
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of games to play.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'snakes_histogram():\n' );
  fprintf ( 1, '  Simulate N one-player games of Snakes and Ladders.\n' );
  fprintf ( 1, '  Use the simulation data to create histograms\n' );
  fprintf ( 1, '  of the estimated PDF and CDF of the game length.\n' );
%
%  Simulate N games.
%
  steps = zeros ( n, 1 );

  for game = 1 : n
    [ steps(game) ] = snakes_one_game ( );
  end
%
%  Report data.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of trials was n =    %d\n', n );
  fprintf ( 1, '  Minimum number of steps was %d\n', min ( steps ) );
  fprintf ( 1, '  Mean number of steps was    %g\n', mean ( steps ) );
  fprintf ( 1, '  Maximum number of steps was %d\n', max ( steps ) );
  fprintf ( 1, '  Standard deviation was      %g\n', std ( steps ) );
%
%  Histogram the PDF.
%
  clf ( );
  nbins = 21;
  norm = 1.0;
  hist ( steps, nbins, norm );
  grid ( 'on' );
  title ( sprintf ( 'Game length PDF for %d Games of Snakes and Ladders', n ) );

  filename = 'snakes_pdf.png';
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  print ( '-dpng', filename );
%
%  Histogram the CDF.
%
  clf ( );
  steps_max = max ( steps );
  nbins = 21;
  edge = linspace ( 0.0, steps_max, nbins );
  cdf = zeros ( nbins, 1 );
  for i = 1 : nbins
    cdf(i) = length ( find ( steps <= edge(i) ) );
  end
  plot ( edge, cdf, 'linewidth', 3 );
  grid ( 'on' );
  xlabel ( 'Game length' );
  ylabel ( 'CDF' );
  title ( sprintf ( 'Game length CDF for %d Games of Snakes and Ladders', n ) );
  filename = 'snakes_cdf.png';
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  print ( '-dpng', filename );

  return
end
