function A = conway_sequence ( n )

%*****************************************************************************80
%
%% conway_sequence() computes the first terms of the Conway challenge sequence.
%
%  Discussion:
%
%    A(1) = 1
%    A(2) = 1
%    A(N) = A(A(N-1)) + A(N-A(N-1))
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    27 March 2024
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Colin Mallows,
%    Conway's Challenge Sequence,
%    American Mathematical Monthly,
%    Volume 98, Number 1, 1991, pages 5-20.
%
%  Input:
%
%    integer n: the number of elements to compute.
%
%  Output:
%
%    integer A(N), the sequence elements.
%
  A = ones ( n, 1 );
  for i = 3 : n
    A(i) = A(A(i-1)) + A(i-A(i-1));
  end

  return
end
