Riordan numbers: Difference between revisions

→‎{{header|Bracmat}}: Added a solution.
(Added Lua)
(→‎{{header|Bracmat}}: Added a solution.)
Line 439:
fi
end sub</syntaxhighlight>
 
=={{header|Bracmat}}==
<syntaxhighlight lang="bracmat">( ( a
=
. !arg:0&1
| !arg:1&0
| !(!arg$A):>0
| (!arg+-1)
* (2*a$(!arg+-1)+3*a$(!arg+-2))
* (!arg+1)^-1
: ?(!arg$A)
)
& "Create a table A that is big enough to memoize 10000 values. All values are initialized to 0."
& "Table elements are selected by using the syntax !index$tableName"
& tbl$(A,10000)
& -1:?n
& whl
' (!n+1:~>32:?n&out$(a$!n))
& "Theoretically, one could just ask for a(10000), but without first computing a(n) for all n < 10000 there is a risk a risk of stack overflow."
& whl'(!n+1:~>10000:?n&a$!n)
& "Apply string pattern matching @(subject:pattern) the the value of a(n) with the special pattern [?variable to find the total length of the string."
& @(a$999:? [?l1000)
& @(a$9999:? [?l10000)
& out$(str$("a(999) has " !l1000 " digits."))
& out$(str$("a(9999) has " !l10000 " 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
3602118427251
a(999) has 472 digits.
a(9999) has 4765 digits.
</pre>
 
=={{header|C++}}==
483

edits