user
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

1. Create a function/procedure/method/subroutine/... to generate the Van Eck sequence of numbers.
2. Use it to display here, on this page:

:   1. The first ten terms of the sequence.
    2. 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.
assistant
(formerly Perl 6)
There is not **a** Van Eck sequence, rather a series of related sequences that differ in their starting value. This task is nominally for the sequence starting with the value 0. This Raku implementation will handle any integer starting value.

Specifically handles:

* OEIS:A181391 - Van Eck sequence starting with 0
* OEIS:A171911 - Van Eck sequence starting with 1
* OEIS:A171912 - Van Eck sequence starting with 2
* OEIS:A171913 - Van Eck sequence starting with 3
* OEIS:A171914 - Van Eck sequence starting with 4
* OEIS:A171915 - Van Eck sequence starting with 5
* OEIS:A171916 - Van Eck sequence starting with 6
* OEIS:A171917 - Van Eck sequence starting with 7
* OEIS:A171918 - Van Eck sequence starting with 8

among others.

Implemented as lazy, extendable lists.

```
sub n-van-ecks ($init) {
    $init, -> $i, {
        state %v;
        state $k;
        $k++;
        my $t  = %v{$i}.defined ?? $k - %v{$i} !! 0;
        %v{$i} = $k;
        $t
    } ... *
}

for <
    A181391 0
    A171911 1
    A171912 2
    A171913 3
    A171914 4
    A171915 5
    A171916 6
    A171917 7
    A171918 8
> -> $seq, $start {

    my @seq = n-van-ecks($start);

    # The task
    put qq:to/END/

    Van Eck sequence OEIS:$seq; with the first term: $start
            First 10 terms: {@seq[^10]}
    Terms 991 through 1000: {@seq[990..999]}
    END
}

```

Output:

```
Van Eck sequence OEIS:A181391; with the first term: 0
        First 10 terms: 0 0 1 0 2 0 2 2 1 6
Terms 991 through 1000: 4 7 30 25 67 225 488 0 10 136


Van Eck sequence OEIS:A171911; with the first term: 1
        First 10 terms: 1 0 0 1 3 0 3 2 0 3
Terms 991 through 1000: 0 6 53 114 302 0 5 9 22 71


Van Eck sequence OEIS:A171912; with the first term: 2
        First 10 terms: 2 0 0 1 0 2 5 0 3 0
Terms 991 through 1000: 8 92 186 0 5 19 41 413 0 5


Van Eck sequence OEIS:A171913; with the first term: 3
        First 10 terms: 3 0 0 1 0 2 0 2 2 1
Terms 991 through 1000: 5 5 1 17 192 0 6 34 38 179


Van Eck sequence OEIS:A171914; with the first term: 4
        First 10 terms: 4 0 0 1 0 2 0 2 2 1
Terms 991 through 1000: 33 410 0 6 149 0 3 267 0 3


Van Eck sequence OEIS:A171915; with the first term: 5
        First 10 terms: 5 0 0 1 0 2 0 2 2 1
Terms 991 through 1000: 60 459 0 7 13 243 0 4 10 211


Van Eck sequence OEIS:A171916; with the first term: 6
        First 10 terms: 6 0 0 1 0 2 0 2 2 1
Terms 991 through 1000: 6 19 11 59 292 0 6 6 1 12


Van Eck sequence OEIS:A171917; with the first term: 7
        First 10 terms: 7 0 0 1 0 2 0 2 2 1
Terms 991 through 1000: 11 7 2 7 2 2 1 34 24 238


Van Eck sequence OEIS:A171918; with the first term: 8
        First 10 terms: 8 0 0 1 0 2 0 2 2 1
Terms 991 through 1000: 16 183 0 6 21 10 249 0 5 48
```