How to resolve the algorithm Padovan n-step number sequences step by step in the XPL0 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Padovan n-step number sequences step by step in the XPL0 programming language

Table of Contents

Problem Statement

As the Fibonacci sequence expands to the Fibonacci n-step number sequences; We similarly expand the Padovan sequence to form these Padovan n-step number sequences. The Fibonacci-like sequences can be defined like this: For this task we similarly define terms of the first 2..n-step Padovan sequences as: The initial values of the sequences are:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Padovan n-step number sequences step by step in the XPL0 programming language

Source code in the xpl0 programming language

\Show some values of the Padovan n-step number sequences
\Sets R(i,j) to the jth element of the ith padovan sequence
\MaxS is the number of sequences to generate and MaxE is the
\ maximum number of elements for each sequence
\MaxS must be >= 2

procedure PadovanSequences ( R, MaxS, MaxE) ;
integer R, MaxS, MaxE;
integer X, N, P;

    function Min( A, B );
    integer A, B;
    return if A < B then A else B;

begin
    \Sequence 2
    for X := 1 to Min( MaxE, 3 ) do R( 2, X ) := 1;
    for X := 4 to MaxE do R( 2, X ) := R( 2, X - 2 ) + R( 2, X - 3 );
    \Sequences 3 and above
    for N := 3 to MaxS do begin
        for X := 1 to Min( MaxE, N + 1 ) do R( N, X ) := R( N - 1, X );
            for X := N + 2 to MaxE do begin
                R( N, X ) := 0;
                for P := X - N - 1 to X - 2 do R( N, X ) := R( N, X ) + R( N, P )
            end \for X
        end \for_N
end; \PadovanSequences

def MAX_SEQUENCES = 8,
    MAX_ELEMENTS = 15;
\Array to hold the Padovan Sequences
integer R( (2+MAX_SEQUENCES), (1+MAX_ELEMENTS)), N, X;
begin   \Calculate and show the sequences
    \Construct the sequences
    PadovanSequences( R, MAX_SEQUENCES, MAX_ELEMENTS );
    \Show the sequences
    Text(0, "Padovan n-step sequences:^m^j" );
    Format(4, 0);
    for N := 2 to MAX_SEQUENCES do begin
        IntOut(0, N);  Text(0, " |");
        for X := 1 to MAX_ELEMENTS do
            RlOut(0, float(R( N, X )));
        CrLf(0);
        end \for N
end

  

You may also check:How to resolve the algorithm Guess the number/With feedback step by step in the Euphoria programming language
You may also check:How to resolve the algorithm Average loop length step by step in the Scala programming language
You may also check:How to resolve the algorithm Terminal control/Clear the screen step by step in the Go programming language
You may also check:How to resolve the algorithm Abelian sandpile model/Identity step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Hunt the Wumpus step by step in the Wren programming language