function [ xtrack, ytrack ] = walker_2d_l2 ( n )

%% WALKER_2D takes a random walk on [-N,+N] x [-N,+N].
%
%  At time K = 1, a walker starts at x = 0, y = 0.
%  At each new time K, the walker randomly steps to north, south, east or west.
%  The walker finishes when reaching (x,y) that is more than N^2 from the origin.
%
%  Input, N, the limits of the walk.
%
%  Output, XTRACK(*), YTRACK(*), a list of the successive locations,
%  including the starting point.
%

%
%  Initialize.
%
  x = 0;
  y = 0;
  k = 1;
  xtrack(k) = x;
  ytrack(k) = y;

  while ( x^2 + y^2 < n^2 )

    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
