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.


100H:
BDOS: PROCEDURE (FN, ARG); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; CALL BDOS(0,0); END EXIT;
PRINT: PROCEDURE (S); DECLARE S ADDRESS; CALL BDOS(9,S); END PRINT;
 
PRINT$NUMBER: PROCEDURE (N);
    DECLARE S (7) BYTE INITIAL ('..... $');
    DECLARE (N, P) ADDRESS, C BASED P BYTE;
    P = .S(5);
DIGIT:
    P = P - 1;
    C = N MOD 10 + '0';
    N = N / 10;
    IF N > 0 THEN GO TO DIGIT;
    CALL PRINT(P);
END PRINT$NUMBER;
 
PRINT$SLICE: PROCEDURE (LIST, N);
    DECLARE (I, N, LIST, L BASED LIST) ADDRESS;
    DO I=0 TO N-1;
        CALL PRINT$NUMBER(L(I));
    END;
    CALL PRINT(.(13,10,'$'));
END PRINT$SLICE;
 
DECLARE ECK (1000) ADDRESS;
DECLARE (I, J) ADDRESS;
 
ECK(0) = 0;
DO I=0 TO LAST(ECK)-1;
    J = I - 1;
    DO WHILE J <> 0FFFFH; /* WHAT IS SIGNED MATH */ 
        IF ECK(I) = ECK(J) THEN DO;
            ECK(I+1) = I-J;
            GO TO NEXT;
        END;
        J = J - 1;
    END;
    ECK(I+1) = 0;
NEXT:
END;
 
CALL PRINT$SLICE(.ECK(0), 10);
CALL PRINT$SLICE(.ECK(990), 10);
CALL EXIT;
EOF