pascltri.icn: Procedure to compute a row of Pascal's Triangle

procedure PascalsTriangle: Pascal triangle row

link pascltri
August 7, 1997; Erik Eid
This file is in the public domain.

    The procedure, when invoked by a call to PascalsTriangle(n), returns
the nth row of Pascal's Triangle in list form.  Pascal's Triangle is a
mathematical structure in which each element of a row is the sum of the
two elements directly above it.  The first few levels are:

   Row 1:          1           Triangle stored as: [[1],
       2:        1   1                              [1, 1],
       3:      1   2   1                            [1, 2, 1],
       4:    1   3   3   1                          [1, 3, 3, 1],
       5:  1   4   6   4   1                        [1, 4, 6, 4, 1]]

For example, PascalsTriangle(4) would return the list [1, 3, 3, 1].

    The procedure fails if n is not an integer or if it is less than one.

Source code | Program Library Page | Icon Home Page