Jump to content

Padovan n-step number sequences: Difference between revisions

Added XPL0 example.
(J)
(Added XPL0 example.)
Line 1,425:
7: 1 1 1 2 3 5 8 13 21 33 53 85 136 218 349
8: 1 1 1 2 3 5 8 13 21 34 54 87 140 225 362
</pre>
 
=={{header|XPL0}}==
{{trans|ALGOL W}}
<syntaxhighlight lang "XPL0">
\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</syntaxhighlight>
{{out}}
<pre>
Padovan n-step sequences:
2 | 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37
3 | 1 1 1 2 3 4 6 9 13 19 28 41 60 88 129
4 | 1 1 1 2 3 5 7 11 17 26 40 61 94 144 221
5 | 1 1 1 2 3 5 8 12 19 30 47 74 116 182 286
6 | 1 1 1 2 3 5 8 13 20 32 51 81 129 205 326
7 | 1 1 1 2 3 5 8 13 21 33 53 85 136 218 349
8 | 1 1 1 2 3 5 8 13 21 34 54 87 140 225 362
</pre>
295

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.