combinatorics¶
Combinatorics Library
- boring_math.combinatorics.comb(n: int, m: int, /, target_top: int = 700, target_bot: int = 5) int¶
C(n,m) - choose m from n.
number of ways
mitems can be taken fromnitems.geared to works efficiently for Python’s arbitrary length integers
slower but comparable to math.comb
default parameters geared to large values of
nandmthe defaults work reasonably well for smaller (human size) values
for inner loops with smaller values,
use
target_top = target_bot = 1or just use
math.comb(n, m)instead
- Parameters:
n – total number of distinct items to choose from
m – number of items to choose
- Returns:
number of ways to choose
mitems fromnitems- Raises:
ValueError – if either
n < 0orm < 0
- boring_math.combinatorics.perm(n: int, m: int, /) int¶
Permutations P(n,m) - number of m orderings taken from n items.
about 5 times slower than the math.perm C code
keeping around for PyPy 3.12+ or Python going JIT
currently the PyPy team is working on 3.11
- Raises:
ValueError – if
n < 0orm < 0