From 562ccb547e42492a133b99804a3b4e14582ea0d2 Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Sun, 4 Oct 2020 11:56:31 +0300 Subject: [PATCH] Add binomial_coefficient --- snippets/binomial_coefficient.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 snippets/binomial_coefficient.md diff --git a/snippets/binomial_coefficient.md b/snippets/binomial_coefficient.md new file mode 100644 index 000000000..92c631fdc --- /dev/null +++ b/snippets/binomial_coefficient.md @@ -0,0 +1,19 @@ +--- +title: binomial_coefficient +tags: math,beginner +--- + +Return the number of ways to choose `k` items from `n` items without repetition and without order. + +- Use `math.comb()` to calculate the binomial coefficient. + +```py +from math import comb + +def binomial_coefficient(n, k): + return comb(n, k) +``` + +```py +binomial_coefficient(8, 2) # 28 +```