function [ xtrack, ytrack ] = walker_2d ( n )

%% WALKER_2D takes a random walk on [-N,+N]x[-N,+n].
%
%  At time K = 1, a walker starts at (x,y) = (0,0).
%  At each new time K, the walker randomly steps to North, South,
%  East, or West.
%
%  Input, N, the limits of the walk.
%
%  Output, XTRACK(*), YTRACK, a list of the successive locations of the walker,
%  including the starting point.
%

%
%  Initialize.
%
  x = 0;
  y = 0;
  k = 1;
  xtrack(k) = x;
  ytrack(k) = y;
%
%  Until you reach boundary, choose a direction at random and take a step.
%
  while ( abs ( x ) < n && abs ( y ) < n )

    i = randi ( [ 1, 4 ] );

    if ( i == 1 )
      y = y + 1;
    elseif ( i == 2 )
      y = y - 1;
    elseif ( i == 3 )
      x = x + 1;
    else
      x = x - 1;
    end

    k = k + 1;
    xtrack(k) = x;
    ytrack(k) = y;

  end

  return
end
