WeixiangYan/CodeTransOcean huggingface dataset:
Task: Van Eck sequence







Python: def van_eck():
    n, seen, val = 0, {}, 0
    while True:
        yield val
        last = {val: n}
        val = n - seen.get(val, n)
        seen.update(last)
        n += 1

if __name__ == '__main__':
    print("Van Eck: first 10 terms:  ", list(islice(van_eck(), 10)))
    print("Van Eck: terms 991 - 1000:", list(islice(van_eck(), 1000))[-10:])





Ada: with Ada.Text_IO;

procedure Van_Eck_Sequence is

   Sequence : array (Natural range 1 .. 1_000) of Natural;

   procedure Calculate_Sequence is
   begin
      Sequence (Sequence'First) := 0;
      for Index in Sequence'First .. Sequence'Last - 1 loop
         Sequence (Index + 1) := 0;
         for I in reverse Sequence'First .. Index - 1 loop
            if Sequence (I) = Sequence (Index) then
               Sequence (Index + 1) := Index - I;
               exit;
            end if;
         end loop;
      end loop;
   end Calculate_Sequence;

   procedure Show (First, Last : in Positive) is
      use Ada.Text_IO;
   begin
      Put ("Element" & First'Image & " .." & Last'Image & " of Van Eck sequence: ");
      for I in First .. Last loop
         Put (Sequence (I)'Image);
      end loop;
      New_Line;
   end Show;

begin
   Calculate_Sequence;
   Show (First =>   1, Last =>    10);
   Show (First => 991, Last => 1_000);
end Van_Eck_Sequence;
Task: Van Eck sequence








VB: Imports System.Linq
Module Module1
    Dim h() As Integer
    Sub sho(i As Integer)
        Console.WriteLine(String.Join(" ", h.Skip(i).Take(10)))
    End Sub
    Sub Main()
        Dim a, b, c, d, f, g As Integer : g = 1000
        h = new Integer(g){} : a = 0 : b = 1 : For c = 2 To g
            f = h(b) : For d = a To 0 Step -1
                If f = h(d) Then h(c) = b - d: Exit For
            Next : a = b : b = c : Next : sho(0) : sho(990)
    End Sub
End Module




Ada: with Ada.Text_IO;

procedure Van_Eck_Sequence is

   Sequence : array (Natural range 1 .. 1_000) of Natural;

   procedure Calculate_Sequence is
   begin
      Sequence (Sequence'First) := 0;
      for Index in Sequence'First .. Sequence'Last - 1 loop
         Sequence (Index + 1) := 0;
         for I in reverse Sequence'First .. Index - 1 loop
            if Sequence (I) = Sequence (Index) then
               Sequence (Index + 1) := Index - I;
               exit;
            end if;
         end loop;
      end loop;
   end Calculate_Sequence;

   procedure Show (First, Last : in Positive) is
      use Ada.Text_IO;
   begin
      Put ("Element" & First'Image & " .." & Last'Image & " of Van Eck sequence: ");
      for I in First .. Last loop
         Put (Sequence (I)'Image);
      end loop;
      New_Line;
   end Show;

begin
   Calculate_Sequence;
   Show (First =>   1, Last =>    10);
   Show (First => 991, Last => 1_000);
end Van_Eck_Sequence;
Task: Van Eck sequence

C: #include <stdlib.h>
#include <stdio.h>

int main(int argc, const char *argv[]) {
  const int max = 1000;
  int *a = malloc(max * sizeof(int));
  for (int n = 0; n < max - 1; n ++) {
    for (int m = n - 1; m >= 0; m --) {
      if (a[m] == a[n]) {
        a[n+1] = n - m;
        break;
      }
    }
  }

  printf("The first ten terms of the Van Eck sequence are:\n");
  for (int i = 0; i < 10; i ++) printf("%d ", a[i]);
  printf("\n\nTerms 991 to 1000 of the sequence are:\n");
  for (int i = 990; i < 1000; i ++) printf("%d ", a[i]);
  putchar('\n');

  return 0;
}
Task: Van Eck sequence



C#: using System.Linq; class Program { static void Main() {
    int a, b, c, d, e, f, g; int[] h = new int[g = 1000];
    for (a = 0, b = 1, c = 2; c < g; a = b, b = c++)
        for (d = a, e = b - d, f = h[b]; e <= b; e++)
            if (f == h[d--]) { h[c] = e; break; }
    void sho(int i) { System.Console.WriteLine(string.Join(" ",
        h.Skip(i).Take(10))); } sho(0); sho(990); } }
Task: Van Eck sequence


C++: #include <iostream>
#include <map>

class van_eck_generator {
public:
    int next() {
        int result = last_term;
        auto iter = last_pos.find(last_term);
        int next_term = (iter != last_pos.end()) ? index - iter->second : 0;
        last_pos[last_term] = index;
        last_term = next_term;
        ++index;
        return result;
    }
private:
    int index = 0;
    int last_term = 0;
    std::map<int, int> last_pos;
};

int main() {
    van_eck_generator gen;
    int i = 0;
    std::cout << "First 10 terms of the Van Eck sequence:\n";
    for (; i < 10; ++i)
        std::cout << gen.next() << ' ';
    for (; i < 990; ++i)
        gen.next();
    std::cout << "\nTerms 991 to 1000 of the sequence:\n";
    for (; i < 1000; ++i)
        std::cout << gen.next() << ' ';
    std::cout << '\n';
    return 0;
}
Task: Van Eck sequence





Java: import java.util.HashMap;
import java.util.Map;

public class VanEckSequence {

    public static void main(String[] args) {
        System.out.println("First 10 terms of Van Eck's sequence:");
        vanEck(1, 10);
        System.out.println("");
        System.out.println("Terms 991 to 1000 of Van Eck's sequence:");
        vanEck(991, 1000);
    }
    
    private static void vanEck(int firstIndex, int lastIndex) {
        Map<Integer,Integer> vanEckMap = new HashMap<>();        
        int last = 0;
        if ( firstIndex == 1 ) {
            System.out.printf("VanEck[%d] = %d%n", 1, 0);
        }
        for ( int n = 2 ; n <= lastIndex ; n++ ) {
            int vanEck = vanEckMap.containsKey(last) ? n - vanEckMap.get(last) : 0;
            vanEckMap.put(last, n);
            last = vanEck;
            if ( n >= firstIndex ) {
                System.out.printf("VanEck[%d] = %d%n", n, vanEck);
            }
        }
        
    }

}
Task: Van Eck sequence







Python: def van_eck():
    n, seen, val = 0, {}, 0
    while True:
        yield val
        last = {val: n}
        val = n - seen.get(val, n)
        seen.update(last)
        n += 1

if __name__ == '__main__':
    print("Van Eck: first 10 terms:  ", list(islice(van_eck(), 10)))
    print("Van Eck: terms 991 - 1000:", list(islice(van_eck(), 1000))[-10:])
Task: Van Eck sequence








VB: Imports System.Linq
Module Module1
    Dim h() As Integer
    Sub sho(i As Integer)
        Console.WriteLine(String.Join(" ", h.Skip(i).Take(10)))
    End Sub
    Sub Main()
        Dim a, b, c, d, f, g As Integer : g = 1000
        h = new Integer(g){} : a = 0 : b = 1 : For c = 2 To g
            f = h(b) : For d = a To 0 Step -1
                If f = h(d) Then h(c) = b - d: Exit For
            Next : a = b : b = c : Next : sho(0) : sho(990)
    End Sub
End Module
Task: Van Eck sequence




Go: package main

import "fmt"

func main() {
    const max = 1000
    a := make([]int, max) 
    for n := 0; n < max-1; n++ {
        for m := n - 1;  m >= 0; m-- {
            if a[m] == a[n] {
                a[n+1] = n - m
                break
            }    
        }
    }
    fmt.Println("The first ten terms of the Van Eck sequence are:")
    fmt.Println(a[:10])
    fmt.Println("\nTerms 991 to 1000 of the sequence are:")
    fmt.Println(a[990:])
}
Task: Van Eck sequence



C#: using System.Linq; class Program { static void Main() {
    int a, b, c, d, e, f, g; int[] h = new int[g = 1000];
    for (a = 0, b = 1, c = 2; c < g; a = b, b = c++)
        for (d = a, e = b - d, f = h[b]; e <= b; e++)
            if (f == h[d--]) { h[c] = e; break; }
    void sho(int i) { System.Console.WriteLine(string.Join(" ",
        h.Skip(i).Take(10))); } sho(0); sho(990); } }








Fortran:       program VanEck
      implicit none
      integer eck(1000), i, j
      
      eck(1) = 0
      do 20 i=1, 999
          do 10 j=i-1, 1, -1
              if (eck(i) .eq. eck(j)) then
                  eck(i+1) = i-j
                  go to 20
              end if
 10       continue
          eck(i+1) = 0
 20   continue
 
      do 30 i=1, 10
 30       write (*,'(I4)',advance='no') eck(i)
      write (*,*)
      
      do 40 i=991, 1000
 40       write (*,'(I4)',advance='no') eck(i)
      write (*,*)
      
      end program
Task: Van Eck sequence


C++: #include <iostream>
#include <map>

class van_eck_generator {
public:
    int next() {
        int result = last_term;
        auto iter = last_pos.find(last_term);
        int next_term = (iter != last_pos.end()) ? index - iter->second : 0;
        last_pos[last_term] = index;
        last_term = next_term;
        ++index;
        return result;
    }
private:
    int index = 0;
    int last_term = 0;
    std::map<int, int> last_pos;
};

int main() {
    van_eck_generator gen;
    int i = 0;
    std::cout << "First 10 terms of the Van Eck sequence:\n";
    for (; i < 10; ++i)
        std::cout << gen.next() << ' ';
    for (; i < 990; ++i)
        gen.next();
    std::cout << "\nTerms 991 to 1000 of the sequence:\n";
    for (; i < 1000; ++i)
        std::cout << gen.next() << ' ';
    std::cout << '\n';
    return 0;
}









Fortran:       program VanEck
      implicit none
      integer eck(1000), i, j
      
      eck(1) = 0
      do 20 i=1, 999
          do 10 j=i-1, 1, -1
              if (eck(i) .eq. eck(j)) then
                  eck(i+1) = i-j
                  go to 20
              end if
 10       continue
          eck(i+1) = 0
 20   continue
 
      do 30 i=1, 10
 30       write (*,'(I4)',advance='no') eck(i)
      write (*,*)
      
      do 40 i=991, 1000
 40       write (*,'(I4)',advance='no') eck(i)
      write (*,*)
      
      end program
Task: Van Eck sequence

C: #include <stdlib.h>
#include <stdio.h>

int main(int argc, const char *argv[]) {
  const int max = 1000;
  int *a = malloc(max * sizeof(int));
  for (int n = 0; n < max - 1; n ++) {
    for (int m = n - 1; m >= 0; m --) {
      if (a[m] == a[n]) {
        a[n+1] = n - m;
        break;
      }
    }
  }

  printf("The first ten terms of the Van Eck sequence are:\n");
  for (int i = 0; i < 10; i ++) printf("%d ", a[i]);
  printf("\n\nTerms 991 to 1000 of the sequence are:\n");
  for (int i = 990; i < 1000; i ++) printf("%d ", a[i]);
  putchar('\n');

  return 0;
}










Fortran:       program VanEck
      implicit none
      integer eck(1000), i, j
      
      eck(1) = 0
      do 20 i=1, 999
          do 10 j=i-1, 1, -1
              if (eck(i) .eq. eck(j)) then
                  eck(i+1) = i-j
                  go to 20
              end if
 10       continue
          eck(i+1) = 0
 20   continue
 
      do 30 i=1, 10
 30       write (*,'(I4)',advance='no') eck(i)
      write (*,*)
      
      do 40 i=991, 1000
 40       write (*,'(I4)',advance='no') eck(i)
      write (*,*)
      
      end program
Task: Van Eck sequence





Java: import java.util.HashMap;
import java.util.Map;

public class VanEckSequence {

    public static void main(String[] args) {
        System.out.println("First 10 terms of Van Eck's sequence:");
        vanEck(1, 10);
        System.out.println("");
        System.out.println("Terms 991 to 1000 of Van Eck's sequence:");
        vanEck(991, 1000);
    }
    
    private static void vanEck(int firstIndex, int lastIndex) {
        Map<Integer,Integer> vanEckMap = new HashMap<>();        
        int last = 0;
        if ( firstIndex == 1 ) {
            System.out.printf("VanEck[%d] = %d%n", 1, 0);
        }
        for ( int n = 2 ; n <= lastIndex ; n++ ) {
            int vanEck = vanEckMap.containsKey(last) ? n - vanEckMap.get(last) : 0;
            vanEckMap.put(last, n);
            last = vanEck;
            if ( n >= firstIndex ) {
                System.out.printf("VanEck[%d] = %d%n", n, vanEck);
            }
        }
        
    }

}






Fortran:       program VanEck
      implicit none
      integer eck(1000), i, j
      
      eck(1) = 0
      do 20 i=1, 999
          do 10 j=i-1, 1, -1
              if (eck(i) .eq. eck(j)) then
                  eck(i+1) = i-j
                  go to 20
              end if
 10       continue
          eck(i+1) = 0
 20   continue
 
      do 30 i=1, 10
 30       write (*,'(I4)',advance='no') eck(i)
      write (*,*)
      
      do 40 i=991, 1000
 40       write (*,'(I4)',advance='no') eck(i)
      write (*,*)
      
      end program
Task: Van Eck sequence







Python: def van_eck():
    n, seen, val = 0, {}, 0
    while True:
        yield val
        last = {val: n}
        val = n - seen.get(val, n)
        seen.update(last)
        n += 1

if __name__ == '__main__':
    print("Van Eck: first 10 terms:  ", list(islice(van_eck(), 10)))
    print("Van Eck: terms 991 - 1000:", list(islice(van_eck(), 1000))[-10:])




Fortran:       program VanEck
      implicit none
      integer eck(1000), i, j
      
      eck(1) = 0
      do 20 i=1, 999
          do 10 j=i-1, 1, -1
              if (eck(i) .eq. eck(j)) then
                  eck(i+1) = i-j
                  go to 20
              end if
 10       continue
          eck(i+1) = 0
 20   continue
 
      do 30 i=1, 10
 30       write (*,'(I4)',advance='no') eck(i)
      write (*,*)
      
      do 40 i=991, 1000
 40       write (*,'(I4)',advance='no') eck(i)
      write (*,*)
      
      end program
Task: Van Eck sequence








VB: Imports System.Linq
Module Module1
    Dim h() As Integer
    Sub sho(i As Integer)
        Console.WriteLine(String.Join(" ", h.Skip(i).Take(10)))
    End Sub
    Sub Main()
        Dim a, b, c, d, f, g As Integer : g = 1000
        h = new Integer(g){} : a = 0 : b = 1 : For c = 2 To g
            f = h(b) : For d = a To 0 Step -1
                If f = h(d) Then h(c) = b - d: Exit For
            Next : a = b : b = c : Next : sho(0) : sho(990)
    End Sub
End Module



Fortran:       program VanEck
      implicit none
      integer eck(1000), i, j
      
      eck(1) = 0
      do 20 i=1, 999
          do 10 j=i-1, 1, -1
              if (eck(i) .eq. eck(j)) then
                  eck(i+1) = i-j
                  go to 20
              end if
 10       continue
          eck(i+1) = 0
 20   continue
 
      do 30 i=1, 10
 30       write (*,'(I4)',advance='no') eck(i)
      write (*,*)
      
      do 40 i=991, 1000
 40       write (*,'(I4)',advance='no') eck(i)
      write (*,*)
      
      end program
Task: Van Eck sequence

C: #include <stdlib.h>
#include <stdio.h>

int main(int argc, const char *argv[]) {
  const int max = 1000;
  int *a = malloc(max * sizeof(int));
  for (int n = 0; n < max - 1; n ++) {
    for (int m = n - 1; m >= 0; m --) {
      if (a[m] == a[n]) {
        a[n+1] = n - m;
        break;
      }
    }
  }

  printf("The first ten terms of the Van Eck sequence are:\n");
  for (int i = 0; i < 10; i ++) printf("%d ", a[i]);
  printf("\n\nTerms 991 to 1000 of the sequence are:\n");
  for (int i = 990; i < 1000; i ++) printf("%d ", a[i]);
  putchar('\n');

  return 0;
}









COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. VAN-ECK.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 CALCULATION.
            02 ECK      PIC 999 OCCURS 1000 TIMES.
            02 I        PIC 9999.
            02 J        PIC 9999.
        01 OUTPUT-FORMAT.
            02 ITEM     PIC ZZ9.
            02 IDX      PIC ZZZ9.
        
        PROCEDURE DIVISION.
        B.  PERFORM GENERATE-ECK.
            PERFORM SHOW VARYING I FROM 1 BY 1 UNTIL I = 11.
            PERFORM SHOW VARYING I FROM 991 BY 1 UNTIL I = 1001.
            STOP RUN.
        
        SHOW.
            MOVE I TO IDX.
            MOVE ECK(I) TO ITEM.
            DISPLAY 'ECK(' IDX ') = ' ITEM.
        
        GENERATE-ECK SECTION.
        B.  SET ECK(1) TO 0.
            SET I TO 1.
            PERFORM GENERATE-TERM 
                VARYING I FROM 2 BY 1 UNTIL I = 1001.
            
        GENERATE-TERM SECTION.
        B.  SUBTRACT 2 FROM I GIVING J.
        LOOP.
            IF J IS LESS THAN 1 GO TO TERM-IS-NEW.
            IF ECK(J) = ECK(I - 1) GO TO TERM-IS-OLD.
            SUBTRACT 1 FROM J.
            GO TO LOOP.
        
        TERM-IS-NEW.
            SET ECK(I) TO 0.
            GO TO DONE.
         
        TERM-IS-OLD.
            COMPUTE ECK(I) = (I - J) - 1.
            
        DONE. EXIT.
Task: Van Eck sequence



C#: using System.Linq; class Program { static void Main() {
    int a, b, c, d, e, f, g; int[] h = new int[g = 1000];
    for (a = 0, b = 1, c = 2; c < g; a = b, b = c++)
        for (d = a, e = b - d, f = h[b]; e <= b; e++)
            if (f == h[d--]) { h[c] = e; break; }
    void sho(int i) { System.Console.WriteLine(string.Join(" ",
        h.Skip(i).Take(10))); } sho(0); sho(990); } }







COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. VAN-ECK.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 CALCULATION.
            02 ECK      PIC 999 OCCURS 1000 TIMES.
            02 I        PIC 9999.
            02 J        PIC 9999.
        01 OUTPUT-FORMAT.
            02 ITEM     PIC ZZ9.
            02 IDX      PIC ZZZ9.
        
        PROCEDURE DIVISION.
        B.  PERFORM GENERATE-ECK.
            PERFORM SHOW VARYING I FROM 1 BY 1 UNTIL I = 11.
            PERFORM SHOW VARYING I FROM 991 BY 1 UNTIL I = 1001.
            STOP RUN.
        
        SHOW.
            MOVE I TO IDX.
            MOVE ECK(I) TO ITEM.
            DISPLAY 'ECK(' IDX ') = ' ITEM.
        
        GENERATE-ECK SECTION.
        B.  SET ECK(1) TO 0.
            SET I TO 1.
            PERFORM GENERATE-TERM 
                VARYING I FROM 2 BY 1 UNTIL I = 1001.
            
        GENERATE-TERM SECTION.
        B.  SUBTRACT 2 FROM I GIVING J.
        LOOP.
            IF J IS LESS THAN 1 GO TO TERM-IS-NEW.
            IF ECK(J) = ECK(I - 1) GO TO TERM-IS-OLD.
            SUBTRACT 1 FROM J.
            GO TO LOOP.
        
        TERM-IS-NEW.
            SET ECK(I) TO 0.
            GO TO DONE.
         
        TERM-IS-OLD.
            COMPUTE ECK(I) = (I - J) - 1.
            
        DONE. EXIT.
Task: Van Eck sequence


C++: #include <iostream>
#include <map>

class van_eck_generator {
public:
    int next() {
        int result = last_term;
        auto iter = last_pos.find(last_term);
        int next_term = (iter != last_pos.end()) ? index - iter->second : 0;
        last_pos[last_term] = index;
        last_term = next_term;
        ++index;
        return result;
    }
private:
    int index = 0;
    int last_term = 0;
    std::map<int, int> last_pos;
};

int main() {
    van_eck_generator gen;
    int i = 0;
    std::cout << "First 10 terms of the Van Eck sequence:\n";
    for (; i < 10; ++i)
        std::cout << gen.next() << ' ';
    for (; i < 990; ++i)
        gen.next();
    std::cout << "\nTerms 991 to 1000 of the sequence:\n";
    for (; i < 1000; ++i)
        std::cout << gen.next() << ' ';
    std::cout << '\n';
    return 0;
}








COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. VAN-ECK.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 CALCULATION.
            02 ECK      PIC 999 OCCURS 1000 TIMES.
            02 I        PIC 9999.
            02 J        PIC 9999.
        01 OUTPUT-FORMAT.
            02 ITEM     PIC ZZ9.
            02 IDX      PIC ZZZ9.
        
        PROCEDURE DIVISION.
        B.  PERFORM GENERATE-ECK.
            PERFORM SHOW VARYING I FROM 1 BY 1 UNTIL I = 11.
            PERFORM SHOW VARYING I FROM 991 BY 1 UNTIL I = 1001.
            STOP RUN.
        
        SHOW.
            MOVE I TO IDX.
            MOVE ECK(I) TO ITEM.
            DISPLAY 'ECK(' IDX ') = ' ITEM.
        
        GENERATE-ECK SECTION.
        B.  SET ECK(1) TO 0.
            SET I TO 1.
            PERFORM GENERATE-TERM 
                VARYING I FROM 2 BY 1 UNTIL I = 1001.
            
        GENERATE-TERM SECTION.
        B.  SUBTRACT 2 FROM I GIVING J.
        LOOP.
            IF J IS LESS THAN 1 GO TO TERM-IS-NEW.
            IF ECK(J) = ECK(I - 1) GO TO TERM-IS-OLD.
            SUBTRACT 1 FROM J.
            GO TO LOOP.
        
        TERM-IS-NEW.
            SET ECK(I) TO 0.
            GO TO DONE.
         
        TERM-IS-OLD.
            COMPUTE ECK(I) = (I - J) - 1.
            
        DONE. EXIT.
Task: Van Eck sequence





Java: import java.util.HashMap;
import java.util.Map;

public class VanEckSequence {

    public static void main(String[] args) {
        System.out.println("First 10 terms of Van Eck's sequence:");
        vanEck(1, 10);
        System.out.println("");
        System.out.println("Terms 991 to 1000 of Van Eck's sequence:");
        vanEck(991, 1000);
    }
    
    private static void vanEck(int firstIndex, int lastIndex) {
        Map<Integer,Integer> vanEckMap = new HashMap<>();        
        int last = 0;
        if ( firstIndex == 1 ) {
            System.out.printf("VanEck[%d] = %d%n", 1, 0);
        }
        for ( int n = 2 ; n <= lastIndex ; n++ ) {
            int vanEck = vanEckMap.containsKey(last) ? n - vanEckMap.get(last) : 0;
            vanEckMap.put(last, n);
            last = vanEck;
            if ( n >= firstIndex ) {
                System.out.printf("VanEck[%d] = %d%n", n, vanEck);
            }
        }
        
    }

}





COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. VAN-ECK.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 CALCULATION.
            02 ECK      PIC 999 OCCURS 1000 TIMES.
            02 I        PIC 9999.
            02 J        PIC 9999.
        01 OUTPUT-FORMAT.
            02 ITEM     PIC ZZ9.
            02 IDX      PIC ZZZ9.
        
        PROCEDURE DIVISION.
        B.  PERFORM GENERATE-ECK.
            PERFORM SHOW VARYING I FROM 1 BY 1 UNTIL I = 11.
            PERFORM SHOW VARYING I FROM 991 BY 1 UNTIL I = 1001.
            STOP RUN.
        
        SHOW.
            MOVE I TO IDX.
            MOVE ECK(I) TO ITEM.
            DISPLAY 'ECK(' IDX ') = ' ITEM.
        
        GENERATE-ECK SECTION.
        B.  SET ECK(1) TO 0.
            SET I TO 1.
            PERFORM GENERATE-TERM 
                VARYING I FROM 2 BY 1 UNTIL I = 1001.
            
        GENERATE-TERM SECTION.
        B.  SUBTRACT 2 FROM I GIVING J.
        LOOP.
            IF J IS LESS THAN 1 GO TO TERM-IS-NEW.
            IF ECK(J) = ECK(I - 1) GO TO TERM-IS-OLD.
            SUBTRACT 1 FROM J.
            GO TO LOOP.
        
        TERM-IS-NEW.
            SET ECK(I) TO 0.
            GO TO DONE.
         
        TERM-IS-OLD.
            COMPUTE ECK(I) = (I - J) - 1.
            
        DONE. EXIT.
Task: Van Eck sequence







Python: def van_eck():
    n, seen, val = 0, {}, 0
    while True:
        yield val
        last = {val: n}
        val = n - seen.get(val, n)
        seen.update(last)
        n += 1

if __name__ == '__main__':
    print("Van Eck: first 10 terms:  ", list(islice(van_eck(), 10)))
    print("Van Eck: terms 991 - 1000:", list(islice(van_eck(), 1000))[-10:])



COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. VAN-ECK.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 CALCULATION.
            02 ECK      PIC 999 OCCURS 1000 TIMES.
            02 I        PIC 9999.
            02 J        PIC 9999.
        01 OUTPUT-FORMAT.
            02 ITEM     PIC ZZ9.
            02 IDX      PIC ZZZ9.
        
        PROCEDURE DIVISION.
        B.  PERFORM GENERATE-ECK.
            PERFORM SHOW VARYING I FROM 1 BY 1 UNTIL I = 11.
            PERFORM SHOW VARYING I FROM 991 BY 1 UNTIL I = 1001.
            STOP RUN.
        
        SHOW.
            MOVE I TO IDX.
            MOVE ECK(I) TO ITEM.
            DISPLAY 'ECK(' IDX ') = ' ITEM.
        
        GENERATE-ECK SECTION.
        B.  SET ECK(1) TO 0.
            SET I TO 1.
            PERFORM GENERATE-TERM 
                VARYING I FROM 2 BY 1 UNTIL I = 1001.
            
        GENERATE-TERM SECTION.
        B.  SUBTRACT 2 FROM I GIVING J.
        LOOP.
            IF J IS LESS THAN 1 GO TO TERM-IS-NEW.
            IF ECK(J) = ECK(I - 1) GO TO TERM-IS-OLD.
            SUBTRACT 1 FROM J.
            GO TO LOOP.
        
        TERM-IS-NEW.
            SET ECK(I) TO 0.
            GO TO DONE.
         
        TERM-IS-OLD.
            COMPUTE ECK(I) = (I - J) - 1.
            
        DONE. EXIT.