Catalan numbers/Pascal's triangle: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 14: Line 14:
[[Pascal's triangle]]
[[Pascal's triangle]]
<br><br>
<br><br>

=={{header|11l}}==
=={{header|11l}}==
{{trans|Python}}
{{trans|Python}}
<syntaxhighlight lang=11l>V n = 15
<syntaxhighlight lang="11l">V n = 15
V t = [0] * (n + 2)
V t = [0] * (n + 2)
t[1] = 1
t[1] = 1
Line 31: Line 30:
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
</pre>
</pre>

=={{header|360 Assembly}}==
=={{header|360 Assembly}}==
For maximum compatibility, this program uses only the basic instruction set.
For maximum compatibility, this program uses only the basic instruction set.
<syntaxhighlight lang=360asm>CATALAN CSECT
<syntaxhighlight lang="360asm">CATALAN CSECT
USING CATALAN,R13,R12
USING CATALAN,R13,R12
SAVEAREA B STM-SAVEAREA(R15)
SAVEAREA B STM-SAVEAREA(R15)
Line 141: Line 139:
02674440
02674440
09694845</pre>
09694845</pre>

=={{header|Action!}}==
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
{{libheader|Action! Tool Kit}}
<syntaxhighlight lang=Action!>INCLUDE "D2:REAL.ACT" ;from the Action! Tool Ki
<syntaxhighlight lang="action!">INCLUDE "D2:REAL.ACT" ;from the Action! Tool Ki


DEFINE PTR="CARD"
DEFINE PTR="CARD"
Line 211: Line 208:
C(15)=9694845
C(15)=9694845
</pre>
</pre>

=={{header|Ada}}==
=={{header|Ada}}==


Uses package Pascal from the Pascal triangle solution[[http://rosettacode.org/wiki/Pascal%27s_triangle#Ada]]
Uses package Pascal from the Pascal triangle solution[[http://rosettacode.org/wiki/Pascal%27s_triangle#Ada]]


<syntaxhighlight lang=Ada>with Ada.Text_IO, Pascal;
<syntaxhighlight lang="ada">with Ada.Text_IO, Pascal;


procedure Catalan is
procedure Catalan is
Line 234: Line 230:


<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845</pre>
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845</pre>

=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
{{trans|C++}}
{{trans|C++}}
<syntaxhighlight lang=algol68>INT n = 15;
<syntaxhighlight lang="algol68">INT n = 15;
[ 0 : n + 1 ]INT t;
[ 0 : n + 1 ]INT t;
t[0] := 0;
t[0] := 0;
Line 251: Line 246:
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
</pre>
</pre>

=={{header|ALGOL W}}==
=={{header|ALGOL W}}==
<syntaxhighlight lang=algolw>begin
<syntaxhighlight lang="algolw">begin
% print the first 15 Catalan numbers from Pascal's triangle %
% print the first 15 Catalan numbers from Pascal's triangle %
integer n;
integer n;
Line 277: Line 271:
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
</pre>
</pre>

=={{header|APL}}==
=={{header|APL}}==
<syntaxhighlight lang=apl>
<syntaxhighlight lang="apl">
⍝ Based heavily on the J solution
⍝ Based heavily on the J solution
CATALAN←{¯1↓↑-/1 ¯1↓¨(⊂⎕IO+0 0)⍉¨0 2⌽¨⊂(⎕IO-⍨⍳N){+\⍣⍺⊢⍵}⍤0 1⊢1⍴⍨N←⍵+2}
CATALAN←{¯1↓↑-/1 ¯1↓¨(⊂⎕IO+0 0)⍉¨0 2⌽¨⊂(⎕IO-⍨⍳N){+\⍣⍺⊢⍵}⍤0 1⊢1⍴⍨N←⍵+2}
Line 288: Line 281:
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
</pre>
</pre>

=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
{{works with|AutoHotkey_L}}
{{works with|AutoHotkey_L}}
<syntaxhighlight lang=AutoHotkey>/* Generate Catalan Numbers
<syntaxhighlight lang="autohotkey">/* Generate Catalan Numbers
//
//
// smgs: 20th Feb, 2014
// smgs: 20th Feb, 2014
Line 325: Line 317:
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
</pre>
</pre>

=={{header|AWK}}==
=={{header|AWK}}==
<syntaxhighlight lang=AWK>
<syntaxhighlight lang="awk">
# syntax: GAWK -f CATALAN_NUMBERS_PASCALS_TRIANGLE.AWK
# syntax: GAWK -f CATALAN_NUMBERS_PASCALS_TRIANGLE.AWK
# converted from C
# converted from C
Line 349: Line 340:
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
</pre>
</pre>

=={{header|Batch File}}==
=={{header|Batch File}}==
<syntaxhighlight lang=dos>@echo off
<syntaxhighlight lang="dos">@echo off
setlocal ENABLEDELAYEDEXPANSION
setlocal ENABLEDELAYEDEXPANSION
set n=15
set n=15
Line 389: Line 379:
2674440
2674440
9694845</pre>
9694845</pre>

=={{header|C}}==
=={{header|C}}==
<syntaxhighlight lang=c>
<syntaxhighlight lang="c">
//This code implements the print of 15 first Catalan's Numbers
//This code implements the print of 15 first Catalan's Numbers
//Formula used:
//Formula used:
Line 443: Line 432:
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
</pre>
</pre>

=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==
{{trans|C++}}
{{trans|C++}}
<syntaxhighlight lang=csharp>
<syntaxhighlight lang="csharp">
int n = 15;
int n = 15;
List<int> t = new List<int>() { 0, 1 };
List<int> t = new List<int>() { 0, 1 };
Line 461: Line 449:
1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845
1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845
</pre>
</pre>

=={{header|C++}}==
=={{header|C++}}==
<syntaxhighlight lang=cpp>// Generate Catalan Numbers
<syntaxhighlight lang="cpp">// Generate Catalan Numbers
//
//
// Nigel Galloway: June 9th., 2012
// Nigel Galloway: June 9th., 2012
Line 483: Line 470:
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
</pre>
</pre>

=={{header|Common Lisp}}==
=={{header|Common Lisp}}==


<syntaxhighlight lang=Lisp>(defun catalan (n)
<syntaxhighlight lang="lisp">(defun catalan (n)
"Return the n-th Catalan number"
"Return the n-th Catalan number"
(if (<= n 1) 1
(if (<= n 1) 1
Line 514: Line 500:
2674440
2674440
9694845</pre>
9694845</pre>

=={{header|D}}==
=={{header|D}}==
{{trans|C++}}
{{trans|C++}}
<syntaxhighlight lang=d>void main() {
<syntaxhighlight lang="d">void main() {
import std.stdio;
import std.stdio;


Line 538: Line 523:
See [https://rosettacode.org/wiki/Catalan_numbers/Pascal%27s_triangle#Pascal Pascal].
See [https://rosettacode.org/wiki/Catalan_numbers/Pascal%27s_triangle#Pascal Pascal].
=={{header|EchoLisp}}==
=={{header|EchoLisp}}==
<syntaxhighlight lang=scheme>
<syntaxhighlight lang="scheme">
(define dim 100)
(define dim 100)
(define-syntax-rule (Tidx i j) (+ i (* dim j)))
(define-syntax-rule (Tidx i j) (+ i (* dim j)))
Line 556: Line 541:
</syntaxhighlight>
</syntaxhighlight>
{{out}}
{{out}}
<syntaxhighlight lang=scheme>
<syntaxhighlight lang="scheme">
;; take elements on diagonal = Catalan numbers
;; take elements on diagonal = Catalan numbers
(for ((i (in-range 0 16))) (write (T (Tidx i i))))
(for ((i (in-range 0 16))) (write (T (Tidx i i))))
Line 562: Line 547:
→ 1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
→ 1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
</syntaxhighlight>
</syntaxhighlight>

=={{header|EDSAC order code}}==
=={{header|EDSAC order code}}==
Rather than store a triangular array, this solution stores the right-hand half of the current row and updates it in place. It uses the third method in the link, e.g. once we have the half row (70, 56, 28, 8, 1), the Catalan number 42 appears as 70 - 28.
Rather than store a triangular array, this solution stores the right-hand half of the current row and updates it in place. It uses the third method in the link, e.g. once we have the half row (70, 56, 28, 8, 1), the Catalan number 42 appears as 70 - 28.
<syntaxhighlight lang=edsac>
<syntaxhighlight lang="edsac">
[Catalan numbers from Pascal triangle, Rosetta Code website.
[Catalan numbers from Pascal triangle, Rosetta Code website.
EDSAC program, Initial Orders 2]
EDSAC program, Initial Orders 2]
Line 644: Line 628:
15 9694845
15 9694845
</pre>
</pre>

=={{header|Elixir}}==
=={{header|Elixir}}==
<syntaxhighlight lang=elixir>defmodule Catalan do
<syntaxhighlight lang="elixir">defmodule Catalan do
def numbers(num) do
def numbers(num) do
{result,_} = Enum.reduce(1..num, {[],{0,1}}, fn i,{list,t0} ->
{result,_} = Enum.reduce(1..num, {[],{0,1}}, fn i,{list,t0} ->
Line 666: Line 649:
[1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845]
[1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845]
</pre>
</pre>

=={{header|Erlang}}==
=={{header|Erlang}}==
<syntaxhighlight lang=erlang>
<syntaxhighlight lang="erlang">
-module(catalin).
-module(catalin).
-compile(export_all).
-compile(export_all).
Line 687: Line 669:
Ans=catl(1,2).
Ans=catl(1,2).
</syntaxhighlight>
</syntaxhighlight>

=={{header|ERRE}}==
=={{header|ERRE}}==
<syntaxhighlight lang=ERRE>
<syntaxhighlight lang="erre">
PROGRAM CATALAN
PROGRAM CATALAN


Line 747: Line 728:
15 9694845
15 9694845
</pre>
</pre>

=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang=fsharp>
<syntaxhighlight lang="fsharp">
let mutable nm=uint64(1)
let mutable nm=uint64(1)
let mutable dm=uint64(1)
let mutable dm=uint64(1)
Line 766: Line 746:
printf ", "
printf ", "
</syntaxhighlight>
</syntaxhighlight>

=={{header|Factor}}==
=={{header|Factor}}==
<syntaxhighlight lang=factor>USING: arrays grouping io kernel math prettyprint sequences ;
<syntaxhighlight lang="factor">USING: arrays grouping io kernel math prettyprint sequences ;
IN: rosetta-code.catalan-pascal
IN: rosetta-code.catalan-pascal


Line 786: Line 765:
1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440
1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440
</pre>
</pre>

=={{header|FreeBASIC}}==
=={{header|FreeBASIC}}==
<syntaxhighlight lang=freebasic>' version 15-09-2015
<syntaxhighlight lang="freebasic">' version 15-09-2015
' compile with: fbc -s console
' compile with: fbc -s console


Line 862: Line 840:
14: 2674440
14: 2674440
15: 9694845</pre>
15: 9694845</pre>

=={{header|Go}}==
=={{header|Go}}==
{{trans|C++}}
{{trans|C++}}
<syntaxhighlight lang=go>package main
<syntaxhighlight lang="go">package main


import "fmt"
import "fmt"
Line 902: Line 879:
15 : 9694845
15 : 9694845
</pre>
</pre>

=={{header|Groovy}}==
=={{header|Groovy}}==
{{trans|C}}
{{trans|C}}
<syntaxhighlight lang=Groovy>
<syntaxhighlight lang="groovy">
class Catalan
class Catalan
{
{
Line 934: Line 910:
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
</pre>
</pre>

=={{header|Haskell}}==
=={{header|Haskell}}==
As required by the task this implementation extracts the Catalan numbers from Pascal's triangle, rather
As required by the task this implementation extracts the Catalan numbers from Pascal's triangle, rather
than calculating them directly. Also, note that it (correctly) produces [1, 1] as the first two numbers.
than calculating them directly. Also, note that it (correctly) produces [1, 1] as the first two numbers.
<syntaxhighlight lang=haskell>import System.Environment (getArgs)
<syntaxhighlight lang="haskell">import System.Environment (getArgs)


-- Pascal's triangle.
-- Pascal's triangle.
Line 963: Line 938:
[1,1,2,5,14,42,132,429,1430,4862,16796,58786,208012,742900,2674440]
[1,1,2,5,14,42,132,429,1430,4862,16796,58786,208012,742900,2674440]
</pre>
</pre>

=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==


Line 969: Line 943:
that aren't used.
that aren't used.


<syntaxhighlight lang=unicon>link math
<syntaxhighlight lang="unicon">link math


procedure main(A)
procedure main(A)
Line 996: Line 970:
->
->
</pre>
</pre>

=={{header|J}}==
=={{header|J}}==


<syntaxhighlight lang=j> Catalan=. }:@:(}.@:((<0 1)&|:) - }:@:((<0 1)&|:@:(2&|.)))@:(i. +/\@]^:[ #&1)@:(2&+)</syntaxhighlight>
<syntaxhighlight lang="j"> Catalan=. }:@:(}.@:((<0 1)&|:) - }:@:((<0 1)&|:@:(2&|.)))@:(i. +/\@]^:[ #&1)@:(2&+)</syntaxhighlight>
{{out|Example use}}
{{out|Example use}}
<syntaxhighlight lang=j> Catalan 15
<syntaxhighlight lang="j"> Catalan 15
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
</syntaxhighlight>
</syntaxhighlight>
Line 1,007: Line 980:
A structured derivation of Catalan follows:
A structured derivation of Catalan follows:


<syntaxhighlight lang=j> o=. @: NB. Composition of verbs (functions)
<syntaxhighlight lang="j"> o=. @: NB. Composition of verbs (functions)
( PascalTriangle=. i. ((+/\@]^:[)) #&1 ) 5
( PascalTriangle=. i. ((+/\@]^:[)) #&1 ) 5
1 1 1 1 1
1 1 1 1 1
Line 1,024: Line 997:
Catalan
Catalan
}:@:(}.@:((<0 1)&|:) - }:@:((<0 1)&|:@:(2&|.)))@:(i. +/\@]^:[ #&1)@:(2&+)</syntaxhighlight>
}:@:(}.@:((<0 1)&|:) - }:@:((<0 1)&|:@:(2&|.)))@:(i. +/\@]^:[ #&1)@:(2&+)</syntaxhighlight>

=={{header|Java}}==
=={{header|Java}}==
{{trans|C++}}
{{trans|C++}}
<syntaxhighlight lang=java>public class Test {
<syntaxhighlight lang="java">public class Test {
public static void main(String[] args) {
public static void main(String[] args) {
int N = 15;
int N = 15;
Line 1,049: Line 1,021:


<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845</pre>
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845</pre>

=={{header|JavaScript}}==
=={{header|JavaScript}}==
===ES5===
===ES5===
Iteration
Iteration
{{trans|C++}}
{{trans|C++}}
<syntaxhighlight lang=javascript>var n = 15;
<syntaxhighlight lang="javascript">var n = 15;
for (var t = [0, 1], i = 1; i <= n; i++) {
for (var t = [0, 1], i = 1; i <= n; i++) {
for (var j = i; j > 1; j--) t[j] += t[j - 1];
for (var j = i; j > 1; j--) t[j] += t[j - 1];
Line 1,070: Line 1,041:
{{Trans|Haskell}}
{{Trans|Haskell}}


<syntaxhighlight lang=JavaScript>(() => {
<syntaxhighlight lang="javascript">(() => {
'use strict';
'use strict';


Line 1,136: Line 1,107:


{{Out}}
{{Out}}
<syntaxhighlight lang=JavaScript>[1,2,5,14,42,132,429,1430,4862,16796,58786,208012,742900,2674440,9694845]</syntaxhighlight>
<syntaxhighlight lang="javascript">[1,2,5,14,42,132,429,1430,4862,16796,58786,208012,742900,2674440,9694845]</syntaxhighlight>

=={{header|jq}}==
=={{header|jq}}==
The first identity (C(2n,n) - C(2n, n-1)) given in the reference is used in accordance with the task description, but it would of course be more efficient to factor out C(2n,n) and use the expression C(2n,n)/(n+1). See also [[Catalan_numbers#jq]] for other alternatives.
The first identity (C(2n,n) - C(2n, n-1)) given in the reference is used in accordance with the task description, but it would of course be more efficient to factor out C(2n,n) and use the expression C(2n,n)/(n+1). See also [[Catalan_numbers#jq]] for other alternatives.
Line 1,143: Line 1,113:
''Warning'': jq uses IEEE 754 64-bit arithmetic,
''Warning'': jq uses IEEE 754 64-bit arithmetic,
so the algorithm used here for Catalan numbers loses precision for n > 30 and fails completely for n > 510.
so the algorithm used here for Catalan numbers loses precision for n > 30 and fails completely for n > 510.
<syntaxhighlight lang=jq>def binomial(n; k):
<syntaxhighlight lang="jq">def binomial(n; k):
if k > n / 2 then binomial(n; n-k)
if k > n / 2 then binomial(n; n-k)
else reduce range(1; k+1) as $i (1; . * (n - $i + 1) / $i)
else reduce range(1; k+1) as $i (1; . * (n - $i + 1) / $i)
Line 1,154: Line 1,124:
(range(0;16), 30, 31, 510, 511) | [., catalan_by_pascal]
(range(0;16), 30, 31, 510, 511) | [., catalan_by_pascal]
{{Out}}
{{Out}}
<syntaxhighlight lang=sh>$ jq -n -c -f Catalan_numbers_Pascal.jq
<syntaxhighlight lang="sh">$ jq -n -c -f Catalan_numbers_Pascal.jq
[0,0]
[0,0]
[1,1]
[1,1]
Line 1,175: Line 1,145:
[510,5.491717746183512e+302]
[510,5.491717746183512e+302]
[511,null]</syntaxhighlight>
[511,null]</syntaxhighlight>

=={{header|Julia}}==
=={{header|Julia}}==
{{trans|Matlab}}
{{trans|Matlab}}
<syntaxhighlight lang=julia># v0.6
<syntaxhighlight lang="julia"># v0.6


function pascal(n::Int)
function pascal(n::Int)
Line 1,197: Line 1,166:
{{out}}
{{out}}
<pre>catalan_num(15) = [1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845]</pre>
<pre>catalan_num(15) = [1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845]</pre>

=={{header|Kotlin}}==
=={{header|Kotlin}}==
<syntaxhighlight lang=scala>// version 1.1.2
<syntaxhighlight lang="scala">// version 1.1.2


import java.math.BigInteger
import java.math.BigInteger
Line 1,243: Line 1,211:
15 : 9694845
15 : 9694845
</pre>
</pre>

=={{header|Lua}}==
=={{header|Lua}}==
For each line of odd-numbered length from Pascal's triangle, print the middle number minus the one immediately to its right.
For each line of odd-numbered length from Pascal's triangle, print the middle number minus the one immediately to its right.
This solution is heavily based on the Lua code to generate Pascal's triangle from the page for that task.
This solution is heavily based on the Lua code to generate Pascal's triangle from the page for that task.
<syntaxhighlight lang=Lua>function nextrow (t)
<syntaxhighlight lang="lua">function nextrow (t)
local ret = {}
local ret = {}
t[0], t[#t + 1] = 0, 0
t[0], t[#t + 1] = 0, 0
Line 1,266: Line 1,233:
{{out}}
{{out}}
<pre>1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440</pre>
<pre>1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440</pre>

=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
{{trans|FreeBasic}}
{{trans|FreeBasic}}
Line 1,277: Line 1,243:
We use & to pass by reference, here anarray, to sub, but because a sub can see anything in module we can change array name inside sub to same as triangle and we can remove arguments (including size).
We use & to pass by reference, here anarray, to sub, but because a sub can see anything in module we can change array name inside sub to same as triangle and we can remove arguments (including size).


<syntaxhighlight lang=M2000 Interpreter>
<syntaxhighlight lang="m2000 interpreter">
Module CatalanNumbers {
Module CatalanNumbers {
Def Integer count, t_row, size=31
Def Integer count, t_row, size=31
Line 1,330: Line 1,296:
15: 9694845
15: 9694845
</pre>
</pre>

=={{header|Maple}}==
=={{header|Maple}}==


<syntaxhighlight lang=maple>catalan:=proc(n)
<syntaxhighlight lang="maple">catalan:=proc(n)
local i,a:=[1],C:=[1];
local i,a:=[1],C:=[1];
for i to n do
for i to n do
Line 1,345: Line 1,310:
catalan(10);
catalan(10);
# [1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796]</syntaxhighlight>
# [1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796]</syntaxhighlight>

=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
This builds the entire Pascal triangle that's needed and holds it in memory. Very inefficienct, but seems to be what is asked in the problem.
This builds the entire Pascal triangle that's needed and holds it in memory. Very inefficienct, but seems to be what is asked in the problem.
<syntaxhighlight lang=Mathematica>nextrow[lastrow_] := Module[{output},
<syntaxhighlight lang="mathematica">nextrow[lastrow_] := Module[{output},
output = ConstantArray[1, Length[lastrow] + 1];
output = ConstantArray[1, Length[lastrow] + 1];
Do[
Do[
Line 1,366: Line 1,330:
{{out}}
{{out}}
<pre>{1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845}</pre>
<pre>{1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845}</pre>

=={{header|MATLAB}} / {{header|Octave}}==
=={{header|MATLAB}} / {{header|Octave}}==


<syntaxhighlight lang=MATLAB>n = 15;
<syntaxhighlight lang="matlab">n = 15;
p = pascal(n + 2);
p = pascal(n + 2);
p(n + 4 : n + 3 : end - 1)' - diag(p, 2)</syntaxhighlight>
p(n + 4 : n + 3 : end - 1)' - diag(p, 2)</syntaxhighlight>
Line 1,389: Line 1,352:
2674440
2674440
9694845</pre>
9694845</pre>

=={{header|Nim}}==
=={{header|Nim}}==
{{trans|Python}}
{{trans|Python}}
<syntaxhighlight lang=nim>const n = 15
<syntaxhighlight lang="nim">const n = 15
var t = newSeq[int](n + 2)
var t = newSeq[int](n + 2)


Line 1,404: Line 1,366:
{{Out}}
{{Out}}
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845 </pre>
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845 </pre>

=={{header|OCaml}}==
=={{header|OCaml}}==
<syntaxhighlight lang=ocaml>
<syntaxhighlight lang="ocaml">
let catalan : int ref = ref 0 in
let catalan : int ref = ref 0 in
Printf.printf "%d ," 1 ;
Printf.printf "%d ," 1 ;
Line 1,425: Line 1,386:
1 ,2,5,14,42,132,429,1430,4862
1 ,2,5,14,42,132,429,1430,4862
</pre>
</pre>

=={{header|Oforth}}==
=={{header|Oforth}}==


<syntaxhighlight lang=Oforth>import: mapping
<syntaxhighlight lang="oforth">import: mapping


: pascal( n -- [] )
: pascal( n -- [] )
Line 1,441: Line 1,401:
[1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845]
[1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845]
</pre>
</pre>

=={{header|PARI/GP}}==
=={{header|PARI/GP}}==
<syntaxhighlight lang=parigp>vector(15,n,binomial(2*n,n)-binomial(2*n,n+1))</syntaxhighlight>
<syntaxhighlight lang="parigp">vector(15,n,binomial(2*n,n)-binomial(2*n,n+1))</syntaxhighlight>
{{out}}
{{out}}
<pre>%1 = [1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845]</pre>
<pre>%1 = [1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845]</pre>

=={{header|Pascal}}==
=={{header|Pascal}}==
<syntaxhighlight lang=pascal>
<syntaxhighlight lang="pascal">
Program CatalanNumbers
Program CatalanNumbers
type
type
Line 1,502: Line 1,460:


</pre>
</pre>

=={{header|Perl}}==
=={{header|Perl}}==
{{trans|C++}}
{{trans|C++}}
<syntaxhighlight lang=Perl>use constant N => 15;
<syntaxhighlight lang="perl">use constant N => 15;
my @t = (0, 1);
my @t = (0, 1);
for(my $i = 1; $i <= N; $i++) {
for(my $i = 1; $i <= N; $i++) {
Line 1,518: Line 1,475:
After the 28th Catalan number, this overflows 64-bit integers. We could add <tt>use bigint;</tt> <tt>use Math::GMP ":constant";</tt> to make it work, albeit not at a fast pace. However we can use a module to do it much faster:
After the 28th Catalan number, this overflows 64-bit integers. We could add <tt>use bigint;</tt> <tt>use Math::GMP ":constant";</tt> to make it work, albeit not at a fast pace. However we can use a module to do it much faster:
{{libheader|ntheory}}
{{libheader|ntheory}}
<syntaxhighlight lang=Perl>use ntheory qw/binomial/;
<syntaxhighlight lang="perl">use ntheory qw/binomial/;
print join(" ", map { binomial( 2*$_, $_) / ($_+1) } 1 .. 1000), "\n";</syntaxhighlight>
print join(" ", map { binomial( 2*$_, $_) / ($_+1) } 1 .. 1000), "\n";</syntaxhighlight>


The <tt>Math::Pari</tt> module also has a binomial, but isn't as fast and overflows its stack after 3400.
The <tt>Math::Pari</tt> module also has a binomial, but isn't as fast and overflows its stack after 3400.

=={{header|Phix}}==
=={{header|Phix}}==
Calculates the minimum pascal triangle in minimum memory. Inspired by the comments in, but not the code of the FreeBasic example
Calculates the minimum pascal triangle in minimum memory. Inspired by the comments in, but not the code of the FreeBasic example
<!--<syntaxhighlight lang=Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">N</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">15</span> <span style="color: #000080;font-style:italic;">-- accurate to 30, nan/inf for anything over 514 (gmp version is below).</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">N</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">15</span> <span style="color: #000080;font-style:italic;">-- accurate to 30, nan/inf for anything over 514 (gmp version is below).</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">catalan</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{},</span> <span style="color: #000080;font-style:italic;">-- (&gt;=1 only)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">catalan</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{},</span> <span style="color: #000080;font-style:italic;">-- (&gt;=1 only)</span>
Line 1,546: Line 1,502:
</pre>
</pre>
Explanatory comments to accompany the above
Explanatory comments to accompany the above
<syntaxhighlight lang=Phix>-- FreeBASIC said:
<syntaxhighlight lang="phix">-- FreeBASIC said:
--' 1 1 1 1 1 1
--' 1 1 1 1 1 1
--' 1 2 3 4 5 6
--' 1 2 3 4 5 6
Line 1,582: Line 1,538:
=== gmp version ===
=== gmp version ===
{{libheader|Phix/mpfr}}
{{libheader|Phix/mpfr}}
<!--<syntaxhighlight lang=Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">\</span><span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 1,617: Line 1,573:
catalan2m: 0.7s 7.0s 64.9s 644s
catalan2m: 0.7s 7.0s 64.9s 644s
</pre>
</pre>

=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
<syntaxhighlight lang=PicoLisp>(de bino (N K)
<syntaxhighlight lang="picolisp">(de bino (N K)
(let f
(let f
'((N)
'((N)
Line 1,633: Line 1,588:
(bino (* 2 N) (inc N)) ) ) )
(bino (* 2 N) (inc N)) ) ) )
(bye)</syntaxhighlight>
(bye)</syntaxhighlight>

=={{header|PureBasic}}==
=={{header|PureBasic}}==
{{trans|C}}
{{trans|C}}
<syntaxhighlight lang=PureBasic>#MAXNUM = 15
<syntaxhighlight lang="purebasic">#MAXNUM = 15
Declare catalan()
Declare catalan()


Line 1,665: Line 1,619:
<pre>
<pre>
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845</pre>
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845</pre>

=={{header|Python}}==
=={{header|Python}}==
===Procedural===
===Procedural===
{{trans|C++}}
{{trans|C++}}
<syntaxhighlight lang=python>>>> n = 15
<syntaxhighlight lang="python">>>> n = 15
>>> t = [0] * (n + 2)
>>> t = [0] * (n + 2)
>>> t[1] = 1
>>> t[1] = 1
Line 1,683: Line 1,636:


{{Works with|Python|2.7}}
{{Works with|Python|2.7}}
<syntaxhighlight lang=python>def catalan_number(n):
<syntaxhighlight lang="python">def catalan_number(n):
nm = dm = 1
nm = dm = 1
for k in range(2, n+1):
for k in range(2, n+1):
Line 1,700: Line 1,653:
{{Trans|Haskell}}
{{Trans|Haskell}}
{{Works with|Python|3.7}}
{{Works with|Python|3.7}}
<syntaxhighlight lang=python>'''Catalan numbers from Pascal's triangle'''
<syntaxhighlight lang="python">'''Catalan numbers from Pascal's triangle'''


from itertools import (islice)
from itertools import (islice)
Line 1,836: Line 1,789:
{{Out}}
{{Out}}
<pre>[1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845]</pre>
<pre>[1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845]</pre>

=={{header|Quackery}}==
=={{header|Quackery}}==


<syntaxhighlight lang=Quackery> [ [] 0 rot 0 join
<syntaxhighlight lang="quackery"> [ [] 0 rot 0 join
witheach
witheach
[ tuck +
[ tuck +
Line 1,858: Line 1,810:


<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845</pre>
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845</pre>

=={{header|Racket}}==
=={{header|Racket}}==
<syntaxhighlight lang=Racket>
<syntaxhighlight lang="racket">
#lang racket
#lang racket


Line 1,873: Line 1,824:
;; 2674440 9694845)
;; 2674440 9694845)
</syntaxhighlight>
</syntaxhighlight>

=={{header|Raku}}==
=={{header|Raku}}==
(formerly Perl 6)
(formerly Perl 6)
{{works with|Rakudo|2015.12}}
{{works with|Rakudo|2015.12}}
<syntaxhighlight lang=raku line>constant @pascal = [1], -> @p { [0, |@p Z+ |@p, 0] } ... *;
<syntaxhighlight lang="raku" line>constant @pascal = [1], -> @p { [0, |@p Z+ |@p, 0] } ... *;


constant @catalan = gather for 2, 4 ... * -> $ix {
constant @catalan = gather for 2, 4 ... * -> $ix {
Line 1,907: Line 1,857:
1767263190
1767263190
6564120420</pre>
6564120420</pre>

=={{header|REXX}}==
=={{header|REXX}}==
===explicit subscripts===
===explicit subscripts===
All of the REXX program examples can handle arbitrary large numbers.
All of the REXX program examples can handle arbitrary large numbers.
<syntaxhighlight lang=rexx>/*REXX program obtains and displays Catalan numbers from a Pascal's triangle. */
<syntaxhighlight lang="rexx">/*REXX program obtains and displays Catalan numbers from a Pascal's triangle. */
parse arg N . /*Obtain the optional argument from CL.*/
parse arg N . /*Obtain the optional argument from CL.*/
if N=='' | N=="," then N=15 /*Not specified? Then use the default.*/
if N=='' | N=="," then N=15 /*Not specified? Then use the default.*/
Line 1,942: Line 1,891:


===implicit subscripts===
===implicit subscripts===
<syntaxhighlight lang=rexx>/*REXX program obtains and displays Catalan numbers from a Pascal's triangle. */
<syntaxhighlight lang="rexx">/*REXX program obtains and displays Catalan numbers from a Pascal's triangle. */
parse arg N . /*Obtain the optional argument from CL.*/
parse arg N . /*Obtain the optional argument from CL.*/
if N=='' | N=="," then N=15 /*Not specified? Then use the default.*/
if N=='' | N=="," then N=15 /*Not specified? Then use the default.*/
Line 1,958: Line 1,907:


===using binomial coefficients===
===using binomial coefficients===
<syntaxhighlight lang=rexx>/*REXX program obtains and displays Catalan numbers from a Pascal's triangle. */
<syntaxhighlight lang="rexx">/*REXX program obtains and displays Catalan numbers from a Pascal's triangle. */
parse arg N . /*Obtain the optional argument from CL.*/
parse arg N . /*Obtain the optional argument from CL.*/
if N=='' | N=="," then N=15 /*Not specified? Then use the default.*/
if N=='' | N=="," then N=15 /*Not specified? Then use the default.*/
Line 1,975: Line 1,924:
===binomial coefficients, memoized===
===binomial coefficients, memoized===
This REXX version uses memoization for the calculation of factorials.
This REXX version uses memoization for the calculation of factorials.
<syntaxhighlight lang=rexx>/*REXX program obtains and displays Catalan numbers from a Pascal's triangle. */
<syntaxhighlight lang="rexx">/*REXX program obtains and displays Catalan numbers from a Pascal's triangle. */
parse arg N . /*Obtain the optional argument from CL.*/
parse arg N . /*Obtain the optional argument from CL.*/
if N=='' | N=="," then N=15 /*Not specified? Then use the default.*/
if N=='' | N=="," then N=15 /*Not specified? Then use the default.*/
Line 1,991: Line 1,940:
if x-y<y then y=x-y; _=1; do j=x-y+1 to x; _=_*j; end; return _/!(y)</syntaxhighlight>
if x-y<y then y=x-y; _=1; do j=x-y+1 to x; _=_*j; end; return _/!(y)</syntaxhighlight>
'''output''' &nbsp; is the same as the 1<sup>st</sup> version. <br><br>
'''output''' &nbsp; is the same as the 1<sup>st</sup> version. <br><br>

=={{header|Ring}}==
=={{header|Ring}}==
<syntaxhighlight lang=ring>
<syntaxhighlight lang="ring">
n=15
n=15
cat = list(n+2)
cat = list(n+2)
Line 2,012: Line 1,960:
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
</pre>
</pre>

=={{header|Ruby}}==
=={{header|Ruby}}==
<syntaxhighlight lang=tcl>def catalan(num)
<syntaxhighlight lang="tcl">def catalan(num)
t = [0, 1] #grows as needed
t = [0, 1] #grows as needed
(1..num).map do |i|
(1..num).map do |i|
Line 2,029: Line 1,976:
[1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845]
[1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845]
</pre>
</pre>

=={{header|Run BASIC}}==
=={{header|Run BASIC}}==
<syntaxhighlight lang=runbasic>n = 15
<syntaxhighlight lang="runbasic">n = 15
dim t(n+2)
dim t(n+2)
t(1) = 1
t(1) = 1
Line 2,042: Line 1,988:
{{out}}
{{out}}
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845 </pre>
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845 </pre>

=={{header|Rust}}==
=={{header|Rust}}==
<syntaxhighlight lang=rust>
<syntaxhighlight lang="rust">


fn main()
fn main()
Line 2,076: Line 2,021:
{{out}}
{{out}}
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845 </pre>
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845 </pre>

=={{header|Scala}}==
=={{header|Scala}}==
<syntaxhighlight lang=Scala>def catalan(n: Int): Int =
<syntaxhighlight lang="scala">def catalan(n: Int): Int =
if (n <= 1) 1
if (n <= 1) 1
else (0 until n).map(i => catalan(i) * catalan(n - i - 1)).sum
else (0 until n).map(i => catalan(i) * catalan(n - i - 1)).sum
Line 2,084: Line 2,028:
(1 to 15).map(catalan(_))</syntaxhighlight>
(1 to 15).map(catalan(_))</syntaxhighlight>
{{Out}}See it in running in your browser by [https://scastie.scala-lang.org/2ybpRZxCTOyrx3mIy8yIDw Scastie (JVM)].
{{Out}}See it in running in your browser by [https://scastie.scala-lang.org/2ybpRZxCTOyrx3mIy8yIDw Scastie (JVM)].

=={{header|Scilab}}==
=={{header|Scilab}}==
<syntaxhighlight lang=text>n=15
<syntaxhighlight lang="text">n=15
t=zeros(1,n+2)
t=zeros(1,n+2)
t(1)=1
t(1)=1
Line 2,115: Line 2,058:
2674440.
2674440.
9694845. </pre>
9694845. </pre>

=={{header|Seed7}}==
=={{header|Seed7}}==
<syntaxhighlight lang=seed7>$ include "seed7_05.s7i";
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";


const proc: main is func
const proc: main is func
Line 2,143: Line 2,085:
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
</pre>
</pre>

=={{header|Sidef}}==
=={{header|Sidef}}==
{{trans|Ruby}}
{{trans|Ruby}}
<syntaxhighlight lang=ruby>func catalan(num) {
<syntaxhighlight lang="ruby">func catalan(num) {
var t = [0, 1]
var t = [0, 1]
(1..num).map { |i|
(1..num).map { |i|
Line 2,159: Line 2,100:
{{out}}
{{out}}
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845</pre>
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845</pre>

=={{header|smart BASIC}}==
=={{header|smart BASIC}}==
<syntaxhighlight lang=qbasic>PRINT "Catalan Numbers from Pascal's Triangle"!PRINT
<syntaxhighlight lang="qbasic">PRINT "Catalan Numbers from Pascal's Triangle"!PRINT
x = 15
x = 15
DIM t(x+2)
DIM t(x+2)
Line 2,175: Line 2,115:
PRINT n,"#######":t(n+1) - t(n)
PRINT n,"#######":t(n+1) - t(n)
NEXT n</syntaxhighlight>
NEXT n</syntaxhighlight>

=={{header|Tcl}}==
=={{header|Tcl}}==
<syntaxhighlight lang=tcl>proc catalan n {
<syntaxhighlight lang="tcl">proc catalan n {
set result {}
set result {}
array set t {0 0 1 1}
array set t {0 0 1 1}
Line 2,192: Line 2,131:
{{out}}
{{out}}
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845</pre>
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845</pre>

=={{header|TI-83 BASIC}}==
=={{header|TI-83 BASIC}}==
<syntaxhighlight lang=ti83b>"CATALAN
<syntaxhighlight lang="ti83b">"CATALAN
15→N
15→N
seq(0,I,1,N+2)→L1
seq(0,I,1,N+2)→L1
Line 2,225: Line 2,163:
9694845
9694845
Done </pre>
Done </pre>

=={{header|Vala}}==
=={{header|Vala}}==
{{trans|C++}}
{{trans|C++}}
<syntaxhighlight lang=vala>void main() {
<syntaxhighlight lang="vala">void main() {
const int N = 15;
const int N = 15;
uint64[] t = {0, 1};
uint64[] t = {0, 1};
Line 2,244: Line 2,181:
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
</pre>
</pre>

=={{header|VBScript}}==
=={{header|VBScript}}==
To run in console mode with cscript.
To run in console mode with cscript.
<syntaxhighlight lang=vbscript>dim t()
<syntaxhighlight lang="vbscript">dim t()
if Wscript.arguments.count=1 then
if Wscript.arguments.count=1 then
n=Wscript.arguments.item(0)
n=Wscript.arguments.item(0)
Line 2,267: Line 2,203:
Wscript.echo t(i+1)-t(i)
Wscript.echo t(i+1)-t(i)
next 'i</syntaxhighlight>
next 'i</syntaxhighlight>

=={{header|Visual Basic}}==
=={{header|Visual Basic}}==
{{trans|Rexx}}
{{trans|Rexx}}
{{works with|Visual Basic|VB6 Standard}}
{{works with|Visual Basic|VB6 Standard}}
<syntaxhighlight lang=vb>
<syntaxhighlight lang="vb">
Sub catalan()
Sub catalan()
Const n = 15
Const n = 15
Line 2,307: Line 2,242:
9694845
9694845
</pre>
</pre>

=={{header|Wren}}==
=={{header|Wren}}==
{{trans|C++}}
{{trans|C++}}
<syntaxhighlight lang=ecmascript>var n = 15
<syntaxhighlight lang="ecmascript">var n = 15
var t = List.filled(n+2, 0)
var t = List.filled(n+2, 0)
t[1] = 1
t[1] = 1
Line 2,325: Line 2,259:
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845
</pre>
</pre>

=={{header|Zig}}==
=={{header|Zig}}==
Uses comptime functionality to compile Pascal's triangle into the object code, then at runtime, it's simply a table lookup. (uses code from AKS primality task.)
Uses comptime functionality to compile Pascal's triangle into the object code, then at runtime, it's simply a table lookup. (uses code from AKS primality task.)
<syntaxhighlight lang=Zig>
<syntaxhighlight lang="zig">
const std = @import("std");
const std = @import("std");
const stdout = std.io.getStdOut().outStream();
const stdout = std.io.getStdOut().outStream();
Line 2,390: Line 2,323:
15 9694845
15 9694845
</pre>
</pre>

=={{header|zkl}}==
=={{header|zkl}}==
{{trans|PARI/GP}} using binomial coefficients.
{{trans|PARI/GP}} using binomial coefficients.
<syntaxhighlight lang=zkl>fcn binomial(n,k){ (1).reduce(k,fcn(p,i,n){ p*(n-i+1)/i },1,n) }
<syntaxhighlight lang="zkl">fcn binomial(n,k){ (1).reduce(k,fcn(p,i,n){ p*(n-i+1)/i },1,n) }
(1).pump(15,List,fcn(n){ binomial(2*n,n)-binomial(2*n,n+1) })</syntaxhighlight>
(1).pump(15,List,fcn(n){ binomial(2*n,n)-binomial(2*n,n+1) })</syntaxhighlight>
{{out}}
{{out}}
Line 2,399: Line 2,331:
L(1,2,5,14,42,132,429,1430,4862,16796,58786,208012,742900,2674440,9694845)
L(1,2,5,14,42,132,429,1430,4862,16796,58786,208012,742900,2674440,9694845)
</pre>
</pre>

=={{header|ZX Spectrum Basic}}==
=={{header|ZX Spectrum Basic}}==
{{trans|C++}}
{{trans|C++}}
<syntaxhighlight lang=zxbasic>10 LET N=15
<syntaxhighlight lang="zxbasic">10 LET N=15
20 DIM t(N+2)
20 DIM t(N+2)
30 LET t(2)=1
30 LET t(2)=1