combinationsWithRep

combinationsWithRep(n, k)

Try it yourself:


combinationsWithRep(): choose with repetition

combinationsWithRep(n, k) counts unordered selections of k items from n types when a type may appear more than once. Selecting three scoops from five flavours, where repeats are allowed, has combinationsWithRep(5, 3) possible outcomes.

Stars and bars

The formula is combinations(n + k − 1, k). It is often called “stars and bars”: k selected items are stars, and separators allocate them among n categories. This is useful for inventory allocations, integer solutions, and multisets.

Compare related counts

Use combinations() when repeated choices are forbidden. Use permutations() if order matters. factorial() gives its factorial expansion. See catalan() for another family of discrete counts.

Input requirements

Use non-negative integer n and k. n represents available types; k represents selections. Be explicit about whether an empty selection is meaningful in your application.

Try Combinations With Rep in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions