Van Eck sequence

From Fōrmulæ wiki
Jump to: navigation, search

This page is a solution to the task Van Eck sequence in the Rosetta Code, written in Fōrmulæ.

Description (from Rosetta Code)

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 previousely.
Example

Using A:

0

Using B:

0 0

Using C:

0 0 1

Using B:

0 0 1 0

Using C: (zero last occured two steps back - before the one)

0 0 1 0 2

Using B:

0 0 1 0 2 0

Using C: (two last occured two steps back - before the zero)

0 0 1 0 2 0 2 2

Using C: (two last occured 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

etc.

Task

  1. Create a function/proceedure/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

Program

VanEckSequencCode.png

Use cases

Let us store the complete sequence:

VanEckSequencCase01.png

The first ten terms of the sequence:

VanEckSequencCase02.png

Terms 991 - to - 1000 of the sequence:

VanEckSequencCase03.png