Graphics and media/Collections of tips and tricks/Pascal's triangle

Unofficial ConTeXt Wiki mirror

Last modified: 2025-01-21


Pascal's Triangle is a triangula array of numbers which is well-known in mathematics. The number at the n-th row and r-th column in the array is the value of combination :

 {n \choose k} 

or

 \binom{n}{k} 

More detailed explanation, you may read wikipedia.

We draw Pascal's triangle using MetaFun and Lua. It can be done by the help of Hans.

First, we define a function to calculate the combination with Lua.

lua code for calculation

The functions MP.p_ncr(n,r) and MP.p_ncr_x() are provided for better and simpler code.

Drawing Pascal's triangle with lines

There are 3 different ways of calculating the value of combination tt.

Drawing Pascal's triangle of numbers