math.comb

Full name
math.comb
Library
math
Syntax

math.comb(n, k)

Description

The math.comb function returns the number of combinations without repetition of n elements taken in blocks of k units.

If the size of the blocks is greater than the number of elements, the function returns 0.

Parameters
  • n: Number of elements to combine
  • k: Size of combinations
Result

The result returned by the math.comb function is an integer.

Examples

We can calculate the number of combinations without repetition of 4 elements taken in blocks of 2 with the following code:

math.comb(4, 2)

6

As mentioned, if the size of the blocks is greater than the number of elements, the function returns 0:

math.comb(4, 7)

0

Submitted by admin on Wed, 01/20/2021 - 10:21