Riordan numbers: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) (Added Perl) |
(Added Action! and Algol W) |
||
Line 24: | Line 24: | ||
<br> |
<br> |
||
=={{header|Action!}}== |
|||
{{Trans|ALGOL W}} |
|||
Finds the first 13 Riordan numbers as Action! is limited to 16 bit integers (signed and unsiged). |
|||
<syntaxhighlight lang="action!"> |
|||
;;; Find some Riordan numbers - limited to the first 13 as the largest integer |
|||
;;; Action! supports is unsigned 16-bit |
|||
;;; sets a to the riordan numbers 0 .. n, a must have n elements |
|||
PROC riordan( CARD n CARD ARRAY a ) |
|||
CARD i |
|||
IF n >= 0 THEN |
|||
a( 0 ) = 1 |
|||
IF n >= 1 THEN |
|||
a( 1 ) = 0 |
|||
FOR i = 2 TO n DO |
|||
a( i ) = ( ( i - 1 ) |
|||
* ( ( 2 * a( i - 1 ) ) |
|||
+ ( 3 * a( i - 2 ) ) |
|||
) |
|||
) |
|||
/ ( i + 1 ) |
|||
OD |
|||
FI |
|||
FI |
|||
RETURN |
|||
PROC Main() |
|||
CARD ARRAY r( 13 ) |
|||
CARD i |
|||
riordan( 13, r ) |
|||
FOR i = 0 TO 12 DO |
|||
Put( ' ) |
|||
PrintC( r( i ) ) |
|||
OD |
|||
RETURN |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
1 0 1 1 3 6 15 36 91 232 603 1585 4213 |
|||
</pre> |
|||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32 and 3.0.3}} |
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32 and 3.0.3}} |
||
Line 115: | Line 158: | ||
The 1000th number is: 51077756867821111314...79942013897484633052 with 472 digits |
The 1000th number is: 51077756867821111314...79942013897484633052 with 472 digits |
||
The 10000th number is: 19927418577260688844...71395322020211157137 with 4765 digits |
The 10000th number is: 19927418577260688844...71395322020211157137 with 4765 digits |
||
</pre> |
|||
=={{header|ALGOL W}}== |
|||
Finds the first 22 Riordan numbers as Algol W is limited to signed 32 bit integers. |
|||
<syntaxhighlight lang="algolw"> |
|||
begin % -- find some Riordan numbers % |
|||
% -- sets a to the Riordan numbers 0 .. n - a must have bounds 0 :: n % |
|||
procedure riordan ( integer value n; integer array a ( * ) ) ; |
|||
if n >= 0 then begin |
|||
a( 0 ) := 1; |
|||
if n >= 1 then begin |
|||
a( 1 ) := 0; |
|||
for i := 2 until n do begin |
|||
a( i ) := ( ( i - 1 ) |
|||
* ( ( 2 * a( i - 1 ) ) |
|||
+ ( 3 * a( i - 2 ) ) |
|||
) |
|||
) |
|||
div ( i + 1 ) |
|||
end for_i |
|||
end if_n_ge_1 |
|||
end riordan ; |
|||
begin % -- show some Riordann numbers % |
|||
integer array r ( 0 :: 21 ); |
|||
integer shown; |
|||
riordan( 21, r ); |
|||
shown := 0; |
|||
for i := 0 until 21 do begin |
|||
writeon( i_w := 9, s_w := 0, " ", r( i ) ); |
|||
shown := shown + 1; |
|||
if shown = 4 then begin |
|||
write(); |
|||
shown := 0 |
|||
end if_shown_eq_4 |
|||
end for_i |
|||
end; |
|||
end. |
|||
</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 |
|||
</pre> |
</pre> |
||