Catalan numbers: Difference between revisions
→{{header|langur}}
Basicgames (talk | contribs) |
Langurmonkey (talk | contribs) |
||
(8 intermediate revisions by 5 users not shown) | |||
Line 564:
next n</syntaxhighlight>
{{out| Output}}<pre>
0 1
1 1
2 2
Line 579 ⟶ 580:
13 742900
14 2674440
15 9694845
</pre>▼
==={{header|FreeBASIC}}===
Line 2,308 ⟶ 2,310:
=={{header|EasyLang}}==
<syntaxhighlight lang="text">
if n = 0
return
.
for i = 0 to 14
.
</syntaxhighlight>
▲</pre>
=={{header|EchoLisp}}==
Line 2,973 ⟶ 2,954:
{{FormulaeEntry|page=https://formulae.org/?script=examples/Catalan_numbers}}
'''Solution'''
'''Direct definition'''
[[File:Fōrmulæ - Catalan numbers 01.png]]
[[File:Fōrmulæ - Catalan numbers 02.png]]
'''Direct definition (alternative)'''
The expression <math>\frac{(2n)!}{(n+1)!\,n!}</math> turns out to be equals to <math>\prod_{k=2}^{n}\frac{n + k}{k}</math>
[[File:Fōrmulæ - Catalan numbers 03.png]]
(same result)
'''No directly defined'''
Recursive definitions are easy to write, but extremely inefficient (specially the first one).
Because a list is intended to be get, the list of previous values can be used as a form of memoization, avoiding recursion.
The next function make use of the "second" form of recursive definition (without recursion):
[[File:Fōrmulæ - Catalan numbers 04.png]]
[[File:Fōrmulæ - Catalan numbers 05.png]]
(same result)
=={{header|GAP}}==
Line 3,767 ⟶ 3,778:
=={{header|langur}}==
{{trans|Perl}}
<syntaxhighlight lang="langur">val .factorial =
val .catalan =
for .i in 0..15 {
Line 6,158 ⟶ 6,170:
{{libheader|Wren-fmt}}
{{libheader|Wren-math}}
<syntaxhighlight lang="
import "./math" for Int
var catalan = Fn.new { |n|
Line 6,221 ⟶ 6,233:
15 9694845
</pre>
=={{header|XLISP}}==
<syntaxhighlight lang="lisp">(defun catalan (n)
|