Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

pascal

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

Number-Theoretic Functions

v0.8-1
GPL (>= 3)
Authors
Hans Werner Borchers
Initial release
2021-04-11

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.