RosettaCodeData/Task/Van-Eck-sequence/00-TASK.txt

47 lines
1.3 KiB
Plaintext

The sequence is generated by following this pseudo-code:
<pre>
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.
</pre>
;Example:
Using A:
:<code>0</code>
Using B:
:<code>0 0</code>
Using C:
:<code>0 0 1</code>
Using B:
:<code>0 0 1 0</code>
Using C: (zero last occurred two steps back - before the one)
:<code>0 0 1 0 2</code>
Using B:
:<code>0 0 1 0 2 0</code>
Using C: (two last occurred two steps back - before the zero)
:<code>0 0 1 0 2 0 2 2</code>
Using C: (two last occurred one step back)
:<code>0 0 1 0 2 0 2 2 1</code>
Using C: (one last appeared six steps back)
:<code>0 0 1 0 2 0 2 2 1 6</code>
...
;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:
* [https://www.youtube.com/watch?v=etMJxB-igrc Don't Know (the Van Eck Sequence) - Numberphile video].
* [[wp:Van_Eck%27s_sequence|Wikipedia Article: Van Eck's Sequence]].
* [[OEIS:A181391| OEIS sequence: A181391]].
<br><br>