How to resolve the algorithm Fibonacci n-step number sequences step by step in the Action! programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Fibonacci n-step number sequences step by step in the Action! programming language

Table of Contents

Problem Statement

These number series are an expansion of the ordinary Fibonacci sequence where: For small values of

n

{\displaystyle n}

, Greek numeric prefixes are sometimes used to individually name each series. Allied sequences can be generated where the initial values are changed:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Fibonacci n-step number sequences step by step in the Action! programming language

Source code in the action! programming language

DEFINE MAX="15"

PROC GenerateSeq(CARD ARRAY init BYTE nInit CARD ARRAY seq BYTE nSeq)
  CARD next
  BYTE i,j,n

  IF nInit
    n=nInit
  ELSE
    n=nSeq
  FI

  FOR i=0 TO n-1
  DO
    seq(i)=init(i)
  OD

  FOR i=n TO nSeq-1
  DO
    next=0
    FOR j=i-nInit TO i-1
    DO
      next==+seq(j)
    OD
    seq(i)=next
  OD
RETURN

PROC PrintSeq(CHAR ARRAY name CARD ARRAY seq BYTE n)
  BYTE i

  PrintF("%S=[",name)
  FOR i=0 TO n-1
  DO
    PrintC(seq(i))
    IF i
      Print(" ")
    ELSE
      PrintE("]")
    FI
  OD
RETURN

PROC SetInverseVideo(CHAR ARRAY text)
  BYTE i

  FOR i=1 TO text(0)
  DO
    text(i)=text(i) OR $80
  OD
RETURN

PROC Test(CHAR ARRAY name CARD ARRAY init CARD ARRAY nInit BYTE nSeq)
  CARD ARRAY seq(MAX)

  SetInverseVideo(name)
  GenerateSeq(init,nInit,seq,nSeq)
  PrintSeq(name,seq,nSeq)
RETURN

PROC Main()
  CARD ARRAY fibInit=[1 1 2 4 8 16 32 64 128 256 512]
  CARD ARRAY lucInit=[2 1]

  Test("lucas",lucInit,2,MAX)
  Test("fibonacci",fibInit,2,MAX)
  Test("tribonacci",fibInit,3,MAX)
  Test("tetranacci",fibInit,4,MAX)
  Test("pentanacci",fibInit,5,MAX)
  Test("hexanacci",fibInit,6,MAX)
  Test("heptanacci",fibInit,7,MAX)
  Test("octanacci",fibInit,8,MAX)
  Test("nonanacci",fibInit,9,MAX)
  Test("decanacci",fibInit,10,MAX)
RETURN

  

You may also check:How to resolve the algorithm Continued fraction/Arithmetic/Construct from rational number step by step in the RATFOR programming language
You may also check:How to resolve the algorithm Safe primes and unsafe primes step by step in the Java programming language
You may also check:How to resolve the algorithm Calendar step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Pangram checker step by step in the D programming language
You may also check:How to resolve the algorithm Leonardo numbers step by step in the OCaml programming language