Riordan numbers: Difference between revisions

(Moved PL/I and PL/M to the correct place)
Line 502:
#":(1e4-1){riordanext^:(1e4) x:1 0
4765</syntaxhighlight>
 
=={{header|jq}}==
 
The C implementation of jq has sufficient arithmetic accuracy for the
first task, but because of the stretch task, the Go implementation has been
used as gojq's integer arithmetic has unbounded accuracy.
 
Using the program below to calculate the first 100,000 Riordan numbers, gojq takes about
4.7 seconds on a 3GHz machine.
 
<syntaxhighlight lang=jq>
def riordan:
{ai: 1, a1: 0}
| ., foreach range(1; infinite) as $i (.;
{ai: ( ($i-1) * (2*.ai + 3*.a1) / ($i+1)),
a1: .ai } )
| .ai ;
 
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
 
def snip($n):
tostring|lpad(6)
+ ($n | tostring | "th: \(.[:10]) .. \(.[-10:]) (\(length) digits)" );
 
"First 32 Riordan numbers:",
foreach limit(100000; riordan) as $riordan (0; .+1;
if . <= 32 then $riordan
elif . == 1000 or . == 10000 or . == 100000 then snip($riordan)
else empty end)
</syntaxhighlight>
 
'''Invocation''': jq -nr -f riordan.jq
 
{{output}}
<pre>
First 32 Riordan numbers:
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
1000th: 5107775686 .. 7484633052 (472 digits)
10000th: 1992741857 .. 0211157137 (4765 digits)
100000th: 5156659846 .. 4709713332 (47704 digits)
</pre>
 
=={{header|Perl}}==
2,484

edits