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, '  MATLAB/Octave version %s\n', version ( ) );
  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' );
%
%  Default N is 500.
%
  if ( nargin < 1 )
    n = 500;
    fprintf ( 1, '\n' );
    fprintf ( 1, '  The input argument N was not supplied.\n' );
    fprintf ( 1, '  Using the default value N = %d\n', n );
  end

  steps = zeros ( n, 1 );

  for game = 1 : n
    [ steps(game) ] = snakes_one_game ( );
  end
%
%  0) Write counts to data file.
%
  filename = sprintf ( 'snakes_histogram_count_%d.csv', n );
  output = fopen ( filename, 'wt' );
  fprintf ( output, '"Game Number", "Game Length"\n' );
  for game = 1 : n
    fprintf ( output, '%d, %d\n', game, steps(game) );
  end
  fclose ( output );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Count data written to "%s"\n', filename );
%
%  1) Histogram the count.
%
  figure ( 1 );
  histogram ( steps, 'Normalization', 'count' );
  grid on
  title ( sprintf ( 'Game length counts for %d Games of Snakes and Ladders', n ) );

  filename = sprintf ( 'snakes_histogram_count_%d.png', n );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  print ( '-dpng', filename );
%
%  2) Histogram the PDF.
%
  figure ( 2 );
  histogram ( steps, 'Normalization', 'pdf' );
  grid on
  title ( sprintf ( 'Game length PDF for %d Games of Snakes and Ladders', n ) );

  filename = sprintf ( 'snakes_histogram_pdf_%d.png', n );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  print ( '-dpng', filename );
%
%  Histogram the CDF.
%
  figure ( 3 );
  histogram ( steps, 'Normalization', 'cdf' );
  grid ( 'on' );
  title ( sprintf ( 'Game length CDF for %d Games of Snakes and Ladders', n ) );

  filename = sprintf ( 'snakes_histogram_cdf_%d.png', n );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  print ( '-dpng', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'SNAKES_HISTOGRAM:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  return
end
