A combination with replacement counts selections when an item may be chosen more than once and order does not matter. Choose this rule for a pizza that can have extra helpings of the same topping: pepperoni, pepperoni, and mushrooms is one combination regardless of selection order. section 2.2.3
For r selections from n distinct available items, the count is (n + r − 1)! / [r!(n − 1)!], or “n + r − 1 choose r.” Placeholder positions turn the repeatable-selection count into a combination count. In Python, compute it with `math.comb(n + r - 1, r)`. section 2.2.3
Three toppings from five ingredients
Set `n = 5` and `r = 3`. Then `math.comb(5 + 3 - 1, 3)` returns `35`. Without replacement, `math.comb(5, 3)` returns only `10`: repeated toppings account for the additional possibilities. section 2.2.3
Five cards, returning each card
If each selected card goes back into a 52-card deck and draw order does not matter, calculate `math.comb(52 + 5 - 1, 5)`, or `math.comb(56, 5)`. The result is `3,819,816` combinations. section 3.2.3
>>> combinations = math.comb(n + r - 1, r)
>>> print(f'Number of combinations with replacement: '
>>> f'{combinations}')
Number of combinations with replacement: 35
The Python listing shows the direct `math.comb(n + r - 1, r)` calculation for five options and three selections. section 2.2.3
