Files
30-seconds-of-code/snippets/binomial-coefficient.md
Angelos Chalaris f6a215e9e3 Kebab file names
2023-04-27 22:00:06 +03:00

439 B

title, tags, cover, firstSeen, lastUpdated
title tags cover firstSeen lastUpdated
Binomial coefficient math digital-nomad-5 2020-10-04T11:56:31+03:00 2020-11-02T19:27:07+02:00

Calculates the number of ways to choose k items from n items without repetition and without order.

  • Use math.comb() to calculate the binomial coefficient.
from math import comb

def binomial_coefficient(n, k):
  return comb(n, k)
binomial_coefficient(8, 2) # 28