How to resolve the algorithm Fibonacci n-step number sequences step by step in the REXX 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 REXX 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 REXX programming language
Source code in the rexx programming language
/*REXX program calculates and displays a N-step Fibonacci sequence(s). */
parse arg FibName values /*allows a Fibonacci name, starter vals*/
if FibName\='' then do; call nStepFib FibName,values; signal done; end
/* [↓] no args specified, show a bunch*/
call nStepFib 'Lucas' , 2 1
call nStepFib 'fibonacci' , 1 1
call nStepFib 'tribonacci' , 1 1 2
call nStepFib 'tetranacci' , 1 1 2 4
call nStepFib 'pentanacci' , 1 1 2 4 8
call nStepFib 'hexanacci' , 1 1 2 4 8 16
call nStepFib 'heptanacci' , 1 1 2 4 8 16 32
call nStepFib 'octonacci' , 1 1 2 4 8 16 32 64
call nStepFib 'nonanacci' , 1 1 2 4 8 16 32 64 128
call nStepFib 'decanacci' , 1 1 2 4 8 16 32 64 128 256
call nStepFib 'undecanacci' , 1 1 2 4 8 16 32 64 128 256 512
call nStepFib 'dodecanacci' , 1 1 2 4 8 16 32 64 128 256 512 1024
call nStepFib '13th-order' , 1 1 2 4 8 16 32 64 128 256 512 1024 2048
done: exit /*stick a fork in it, we're all done. */
/*────────────────────────────────────────────────────────────────────────────*/
nStepFib: procedure; parse arg Fname,vals,m; if m=='' then m=30; L=
N=words(vals)
do pop=1 for N /*use N initial values. */
@.pop=word(vals,pop) /*populate initial numbers*/
end /*pop*/
do j=1 for m /*calculate M Fib numbers.*/
if j>N then do; @.j=0 /*initialize the sum to 0.*/
do k=j-N for N /*sum the last N numbers.*/
@.j=@.j+@.k /*add the [N-j]th number.*/
end /*k*/
end
L=L @.j /*append Fib number──►list*/
end /*j*/
say right(Fname,11)'[sum'right(N,3) "terms]:" strip(L) '···'
return
You may also check:How to resolve the algorithm File extension is in extensions list step by step in the Nim programming language
You may also check:How to resolve the algorithm Safe primes and unsafe primes step by step in the REXX programming language
You may also check:How to resolve the algorithm Sorting algorithms/Heapsort step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm Execute a system command step by step in the SETL programming language
You may also check:How to resolve the algorithm Factors of a Mersenne number step by step in the CoffeeScript programming language