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.


 
/* ARM assembly AARCH64 Raspberry PI 3B */
/*  program vanEckSerie64.s   */
 
/*******************************************/
/* Constantes file                         */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeConstantesARM64.inc"
 
.equ MAXI,      1000
 
/*********************************/
/* Initialized data              */
/*********************************/
.data
sMessResultElement:    .asciz " @ "
szCarriageReturn:   .asciz "\n"
 
/*********************************/
/* UnInitialized data            */
/*********************************/
.bss  
sZoneConv:                  .skip 24
TableVanEck:                .skip 8 * MAXI
/*********************************/
/*  code section                 */
/*********************************/
.text
.global main 
main:                             // entry of program 
    mov x2,#0                     // begin first element
    mov x3,#0                     // current counter
    ldr x4,qAdrTableVanEck        // table address
    str x2,[x4,x3,lsl 3]          // store first zéro
1:                                // begin loop 
    mov x5,x3                     // init current indice
2:
    sub x5,x5,1                   // decrement
    cmp x5,0                      // end table ?
    blt 3f
    ldr x6,[x4,x5,lsl 3]          // load element
    cmp x6,x2                     // and compare with the last element
    bne 2b                        // not equal
    sub x2,x3,x5                  // else compute gap
    b 4f
3:
    mov x2,#0                     // first, move zero to next element
4:
    add x3,x3,#1                  // increment counter
    str x2,[x4,x3,lsl 3]          // and store new element
    cmp x3,MAXI
    blt 1b
 
    mov x2,0
5:                                // loop display ten elements
    ldr x0,[x4,x2,lsl 3]
    ldr x1,qAdrsZoneConv
    bl conversion10               // call décimal conversion
    ldr x0,qAdrsMessResultElement
    ldr x1,qAdrsZoneConv          // insert conversion in message
    bl strInsertAtCharInc
    mov x1,0                      // final zéro
    strb w1,[x0,5]                // 
    bl affichageMess              // display message
    add x2,x2,1                   // increment indice
    cmp x2,10                     // end ?
    blt 5b                        // no -> loop
    ldr x0,qAdrszCarriageReturn
    bl affichageMess
 
    mov x2,MAXI - 10
6:                                // loop display ten elements 990-999
    ldr x0,[x4,x2,lsl 3]
    ldr x1,qAdrsZoneConv
    bl conversion10               // call décimal conversion
    ldr x0,qAdrsMessResultElement
    ldr x1,qAdrsZoneConv          // insert conversion in message
    bl strInsertAtCharInc
    mov x1,0                      // final zéro
    strb w1,[x0,5]                // 
    bl affichageMess              // display message
    add x2,x2,1                   // increment indice
    cmp x2,MAXI                   // end ?
    blt 6b                        // no -> loop
    ldr x0,qAdrszCarriageReturn
    bl affichageMess
 
100:                              // standard end of the program 
    mov x0, 0                     // return code
    mov x8, EXIT                  // request to exit program
    svc 0                         // perform the system call
qAdrszCarriageReturn:    .quad szCarriageReturn
qAdrsMessResultElement:  .quad sMessResultElement
qAdrsZoneConv:           .quad sZoneConv  
qAdrTableVanEck:         .quad TableVanEck
/********************************************************/
/*        File Include fonctions                        */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
 