How to resolve the algorithm Van Eck sequence step by step in the Fortran programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Van Eck sequence step by step in the Fortran programming language

Table of Contents

Problem Statement

The sequence is generated by following this pseudo-code:

Using A: Using B: Using C: Using B: Using C: (zero last occurred two steps back - before the one) Using B: Using C: (two last occurred two steps back - before the zero) Using C: (two last occurred one step back) Using C: (one last appeared six steps back) ...

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Van Eck sequence step by step in the Fortran programming language

Source code in the fortran programming language

      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


  

You may also check:How to resolve the algorithm Repeat a string step by step in the REXX programming language
You may also check:How to resolve the algorithm Compound data type step by step in the KonsolScript programming language
You may also check:How to resolve the algorithm Forward difference step by step in the Forth programming language
You may also check:How to resolve the algorithm Unicode variable names step by step in the C programming language
You may also check:How to resolve the algorithm Zig-zag matrix step by step in the VBA programming language