Functions¶
- boring_math.combinatorics.comb(n: int, m: int, /, target_top: int = 700, target_bot: int = 5) int¶
C(n, m) - combinations
Number of ways m items can be taken from n items. Geared to works efficiently for Python’s arbitrary length integers.
- param n:
Total number of distinct items to choose from.
- param m:
Number of items to choose, order does not matter.
- param target_top:
Config param to cancel factors before multiplying.
- param target_bot:
Config param to cancel factors before multiplying.
- returns:
Number of ways to choose m items from n items.
- raises ValueError:
If either n < 0 or m < 0.
Note
slower but comparable to math.comb
default parameters geared to large values of n and m
defaults work reasonably well for smaller (human size) values
Tip
For inner loops with smaller values, use
target_top = target_bot = 1or just use math.comb(n, m) instead.
- boring_math.combinatorics.perm(n: int, m: int, /) int¶
P(n, m) - permutations
Number of orderings of m items taken from n items.
- param n:
Total number of distinct items to order.
- param m:
Number of items in each ordering.
- returns:
Number of arrangements of m items from n items.
- raises ValueError:
If either n < 0 or m < 0.
Warning
About 5 times slower than the math.perm C code.