function check = gray_code_check ( n, t )

%*****************************************************************************80
%
%% gray_code_check() checks a Gray code element.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    23 January 2011
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of digits in each element.
%    N must be positive.
%
%    integer T(N), an element of the Gray code.
%    Each entry T(I) is either 0 or 1.
%
%  Output:
%
%    boolean CHECK, error flag.
%    true, T represents a Gray code.
%    false, T does not represent a Gray code.
%
  check = true;

  if ( n < 1 )
    check = false;
    return
  end

  for i = 1 : n

    if ( t(i) ~= 0 && t(i) ~= 1 )
      check = false;
      return
    end

  end

  return
end
