  function nTosses = Gap(N)
% Simulates a game where you keep tossing a fair coin
% until |Heads - Tails| = N

  Heads = 0; Tails = 0;
  nTosses = 0;
  while abs(Heads-Tails)<N
     nTosses = nTosses + 1;
     if rand <.5
        Heads = Heads + 1;
     else
        Tails = Tails + 1;
     end
  end
  