function easywalk ( m )

%*****************************************************************************80
%
%% easywalk() exactly analyzes a walk from the corner of (M+1,M+1) to (1,1).
%
%  Discussion:
%
%    A pedestrian begins M blocks east and M blocks north of a destination.
%    At each intersection, there is a stop light which is set randomly,
%    and switches after 1 minute.
%    Until reaching avenue 1 or street 1, the pedestrian always crosses
%    the intersection in accordance with the stop light.
%    Thereafter, the pedestrian must wait at each stop light encountered.
%    What is the average wait for stop lights?
%
%  Example:
%
%      M       Time
%
%      2    0.75
%      5    1.23046875
%     10    1.762
%     20    2.5074
%     50    3.97946
%    100    5.6348479
%   1000   17.839
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    28 January 2018
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Digital Dice: Computational Solutions to Practical Probability Problems,
%    Princeton, 2008,
%    ISBN: 978-0-691-15821-1.
%
%  Input:
%
%    integer M, the number of blocks east and north.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'easywalk():\n' );
  fprintf ( 1, '  A pedestrian begins %d blocks east and %d blocks north of a destination.\n', m, m );
  fprintf ( 1, '  At each intersection, there is a stop light which is set randomly,\n' );
  fprintf ( 1, '  and switches after 1 minute.\n' );
  fprintf ( 1, '  Until reaching avenue 1 or street 1, the pedestrian always crosses\n' );
  fprintf ( 1, '  the intersection in accordance with the stop light.\n' );
  fprintf ( 1, '  Thereafter, the pedestrian must wait at each stop light encountered.\n' );
  fprintf ( 1, '  What is the exact expected wait for stop lights?\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Use graphics to display the expected results.\n' );

  for j = 1 : m + 1
    E(j,1) = ( j - 1 ) / 2;
    E(1,j) = E(j,1);
  end

  for k = 2 : m + 1
    for j = 2 : m + 1
      E(j,k) = ( E(j-1,k) + E(j,k-1) ) / 2;
    end
  end

  for k = 1 : m + 1
    x(k) = k;
    y(k) = E(k,k);
  end
%
%  Graphics.
%
  clf ( );
  plot ( x, y, 'linewidth', 3 );
  grid ( 'on' );
  title ( 'easywalk' );
  xlabel ( 'MxM city blocks' );
  ylabel ( 'Expected number of stoplights to wait for.' );
  filename = 'easywalk.png';
  print ( '-dpng', filename )
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
 
  return
end
