Task

Print out the first   15   Catalan numbers by extracting them from Pascal's triangle.



See

   Catalan Numbers and the Pascal Triangle.     This method enables calculation of Catalan Numbers using only addition and subtraction.
   Catalan's Triangle for a Number Triangle that generates Catalan Numbers using only addition.
   Sequence A000108 on OEIS has a lot of information on Catalan Numbers.
Related Tasks

Pascal's triangle

begin
    % print the first 15 Catalan numbers from Pascal's triangle %
    integer n;
    n := 15;
    begin
        integer array pascalLine ( 1 :: n + 1 );
        % the Catalan numbers are the differences between the middle and middle - 1 numbers of the odd %
        % lines of Pascal's triangle (lines with 3 or more numbers)                                    %
        % note - we only need to calculate the left side of the triangle                               %
        pascalLine( 1 ) := 1;
        for c := 2 until n + 1 do begin
            % even line %
            for i := c - 1 step -1 until 2 do pascalLine( i ) := pascalLine( i - 1 ) + pascalLine( i );
            pascalLine( c ) := pascalLine( c - 1 );
            % odd line %
            for i := c     step -1 until 2 do pascalLine( i ) := pascalLine( i - 1 ) + pascalLine( i );
            writeon( i_w := 1, s_w := 0, " ", pascalLine( c ) - pascalLine( c - 1 ) )
        end for_c
    end
end.