function s = coin_streak ( n, v )

%*****************************************************************************80
%
%% coin_streak() counts streaks in a sequence of coin flips.
%
%  Example:
%
%    V = (   -1  -1   +1   -1   +1  +1  +1   -1  -1   +1   )
%    S = (  0  -1  -2 | +1 | -1 | +1  +2  +3 | -1  -2 | +1 )
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    21 February 2016
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of tosses.
%
%    real V(N), the sequence of coin flips.
%    -1 = tails, +1 = heads.
%
%  Output:
%
%    real S(N+1), indicates streaks.
%
  s = zeros ( n + 1, 1 );

  s(1) = 0;
  s(2) = v(1);

  for i = 3 : n + 1
    s(i) = v(i-1);
    if ( v(i-2) == v(i-1) )
      s(i) = s(i) + s(i-1);
    end
  end

  return
end
