Riordan numbers: Difference between revisions

Add PARI/GP implementation
(Add Mathematica/Wolfram Language implementation)
(Add PARI/GP implementation)
 
Line 1,117:
<pre>The 1000th Riordan number has 472 digits.
The 10000th Riordan number has 4765 digits.
</pre>
 
=={{header|PARI/GP}}==
<syntaxhighlight lang="PARI/GP">
\\ Increase the stack size if necessary
default(parisize, "32M"); \\ Increase to 32MB, adjust if necessary
 
Riordan(N) = {
my(a = vector(N));
a[1] = 1; a[2] = 0; a[3] = 1;
for (n = 3, N-1,
a[n+1] = ((n - 1) * (2 * a[n] + 3 * a[n-1]) \ (n + 1)); \\ Integer division
);
return(a);
}
 
rios = Riordan(10000);
 
\\ Now print the first 32 elements in the desired format
for (i = 1, 32,{
print1(rios[i]," ")
});
print("")
 
\\ Print the number of digits for the 1000th and 10000th Riordan numbers
print("The 1,000th Riordan has ", #digits(rios[1000]), " digits.");
print("The 10,000th Riordan has ", #digits(rios[10000]), " digits.");
</syntaxhighlight>
{{out}}
<pre>
1 0 1 1 3 6 15 36 91 232 603 1585 4213 11298 30537 83097 227475 625992 1730787 4805595 13393689 37458330 105089229 295673994 834086421 2358641376 6684761125 18985057351 54022715451 154000562758 439742222071 1257643249140
The 1,000th Riordan has 472 digits.
The 10,000th Riordan has 4765 digits.
 
</pre>
 
338

edits