function average = walker_2d_max_average ( n, m )

%% WALKER_2D_MAX_AVERAGE averages the length of a random walk on [-N,+N]x[-N,+N].
%
%  It is assumed the walker starts at (0,0), and randomly steps North,
%  South, East or West until the X or Y coordinate has absolute value N.  
%  The number of steps taken is the length of the walk.
%
%  This program takes M random walks, and reports the average length.
%
  average = 0.0;

  for i = 1 : m
    track = walker_2d_max ( n );
    average = average + length ( track ) - 1;
  end

  average = average / m;

  return
end
