function idx=firstChange(v)
%firstChange index of first change in a vector
%
% takes a vector v and returns the index of
% the element before the first change
%
% Example:
%
%   @@@ Fill this in later
%
% P. Conrad for CISC106 10/11/06


firstValue = v(1);

for k = 2:length(v)

  % if this element of v is different
  % then the previous element was the one
  % whose index we need to return


  if ( v(k) ~= firstValue)
    idx = k - 1;
    return;
  end;
end;

% postcondition:  If I got all the way thru
%  the loop, and did not return yet, it means
%  that the statement v(k) ~= firstvalue was
%  FALSE for EVERY value of k.
% Therefore I can conclude:

idx = 0;
end


