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.


MODULE VanEck;
FROM InOut IMPORT WriteCard, WriteLn;
 
VAR i, j: CARDINAL;
    eck: ARRAY [1..1000] OF CARDINAL;
 
BEGIN
    FOR i := 1 TO 1000 DO
        eck[i] := 0;
    END;
    FOR i := 1 TO 999 DO
        j := i-1;
        WHILE (j > 0) AND (eck[i] <> eck[j]) DO
            DEC(j);
        END;
        IF j <> 0 THEN
            eck[i+1] := i-j;
        END;
    END;
 
    FOR i := 1 TO 10 DO
        WriteCard(eck[i], 4);
    END;
    WriteLn();
 
    FOR i := 991 TO 1000 DO
        WriteCard(eck[i], 4);
    END;
    WriteLn();
END VanEck.