pascal: Pascal Triangle

Pascal triangleR Documentation

Pascal Triangle

Description

Generates the Pascal triangle in rectangular form.

Usage

pascal_triangle(n)

Arguments

n

integer number

Details

Pascal numbers will be generated with the usual recursion formula and stored in a rectangular scheme.

For n>50 integer overflow would happen, so use the arbitrary precision version gmp::chooseZ(n, 0:n) instead for calculating binomial numbers.

Value

Returns the Pascal triangle as an (n+1)x(n+1) rectangle with zeros filled in.

References

See Wolfram MathWorld or the Wikipedia.

Examples

n <- 5; P <- pascal_triangle(n)
for (i in 1:(n+1)) {
    cat(P[i, 1:i], '\n')
}
## 1 
## 1 1 
## 1 2 1 
## 1 3 3 1 
## 1 4 6 4 1 
## 1 5 10 10 5 1 

## Not run: 
P <- pascal_triangle(50)
max(P[51, ])
## [1] 126410606437752

## End(Not run)

numbers documentation built on Nov. 23, 2022, 9:06 a.m.