How to resolve the algorithm Fibonacci n-step number sequences step by step in the ALGOL 68 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 ALGOL 68 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 ALGOL 68 programming language
Source code in the algol programming language
# returns an array of the first required count elements of an a n-step fibonacci sequence #
# the initial values are taken from the init array #
PROC n step fibonacci sequence = ( []INT init, INT required count )[]INT:
BEGIN
[ 1 : required count ]INT result;
[]INT initial values = init[ AT 1 ];
INT step = UPB initial values;
# install the initial values #
FOR n TO step DO result[ n ] := initial values[ n ] OD;
# calculate the rest of the sequence #
FOR n FROM step + 1 TO required count DO
result[ n ] := 0;
FOR p FROM n - step TO n - 1 DO result[ n ] +:= result[ p ] OD
OD;
result
END; # required count #
# prints the elements of a sequence #
PROC print sequence = ( STRING legend, []INT sequence )VOID:
BEGIN
print( ( legend, ":" ) );
FOR e FROM LWB sequence TO UPB sequence DO print( ( " ", whole( sequence[ e ], 0 ) ) ) OD;
print( ( newline ) )
END; # print sequence #
# print some sequences #
print sequence( "fibonacci ", n step fibonacci sequence( ( 1, 1 ), 10 ) );
print sequence( "tribonacci ", n step fibonacci sequence( ( 1, 1, 2 ), 10 ) );
print sequence( "tetrabonacci", n step fibonacci sequence( ( 1, 1, 2, 4 ), 10 ) );
print sequence( "lucus ", n step fibonacci sequence( ( 2, 1 ), 10 ) )
You may also check:How to resolve the algorithm Program name step by step in the vbscript programming language
You may also check:How to resolve the algorithm Evolutionary algorithm step by step in the Rust programming language
You may also check:How to resolve the algorithm Unix/ls step by step in the C++ programming language
You may also check:How to resolve the algorithm Queue/Usage step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm URL encoding step by step in the Free Pascal programming language