The sequence is generated by following this pseudo-code:

A:  The first term is zero.
    Repeatedly apply:
        If the last term is *new* to the sequence so far then:
B:          The next term is zero.
        Otherwise:
C:          The next term is how far back this last term occured previously.



Example

Using A:

0
Using B:

0 0
Using C:

0 0 1
Using B:

0 0 1 0
Using C: (zero last occurred two steps back - before the one)

0 0 1 0 2
Using B:

0 0 1 0 2 0
Using C: (two last occurred two steps back - before the zero)

0 0 1 0 2 0 2 2
Using C: (two last occurred one step back)

0 0 1 0 2 0 2 2 1
Using C: (one last appeared six steps back)

0 0 1 0 2 0 2 2 1 6
...



Task

 Create a function/procedure/method/subroutine/... to generate the Van Eck sequence of numbers.
 Use it to display here, on this page:
 The first ten terms of the sequence.
 Terms 991 - to - 1000 of the sequence.


References

 Don't Know (the Van Eck Sequence) - Numberphile video.
 Wikipedia Article: Van Eck's Sequence.
  OEIS sequence: A181391.


with Ada.Text_IO;
 
procedure Van_Eck_Sequence is
 
   Sequence : array (Natural range 1 .. 1_000) of Natural;
 
   procedure Calculate_Sequence is
   begin
      Sequence (Sequence'First) := 0;
      for Index in Sequence'First .. Sequence'Last - 1 loop
         Sequence (Index + 1) := 0;
         for I in reverse Sequence'First .. Index - 1 loop
            if Sequence (I) = Sequence (Index) then
               Sequence (Index + 1) := Index - I;
               exit;
            end if;
         end loop;
      end loop;
   end Calculate_Sequence;
 
   procedure Show (First, Last : in Positive) is
      use Ada.Text_IO;
   begin
      Put ("Element" & First'Image & " .." & Last'Image & " of Van Eck sequence: ");
      for I in First .. Last loop
         Put (Sequence (I)'Image);
      end loop;
      New_Line;
   end Show;
 
begin
   Calculate_Sequence;
   Show (First =>   1, Last =>    10);
   Show (First => 991, Last => 1_000);
end Van_Eck_Sequence;