Suppose you buy 5 pieces of fruit from three kinds: apples, pears and tangerines. You may buy several of the same kind, and the order of choosing does not matter. The number of ways to choose r items from n different kinds with repetition allowed is a combination with repetition, written ₙHᵣ in Korean textbooks. This problem is ₃H₅.

Counting case by case (5 apples; 4 apples and 1 pear; and so on) takes too long. So change the picture. Draw each chosen fruit as a circle (○) and each place where the kind changes as a bar (│). Then 1 apple, 2 pears and 2 tangerines becomes ○│○○│○○. Separating three kinds needs 2 bars, so each way of buying matches exactly one row of 5 circles and 2 bars.

○│○○│○○
○│○○│○○ means 1 apple, 2 pears and 2 tangerines

Now the problem becomes choosing where the 2 bars go among 7 positions, which can be done in ₇C₂ = 21 ways. In general you arrange r circles and n − 1 bars, so ₙHᵣ = ₙ₊ᵣ₋₁Cᵣ. The key is not to memorise a new formula but to turn the problem into arranging a row in which some items are identical.

If every kind must be bought at least once, put one of each kind in the basket first and choose the rest with repetition. Buying 5 from three kinds with at least one of each leaves 2 to choose: ₃H₂ = ₄C₂ = 6 ways. The same idea counts the non-negative integer solutions of x + y + z = 5: ₃H₅ = 21.

In this lab, you set the number of kinds n and the number to choose r, then tap positions to switch between circles and bars and draw one way. Once there are (number of kinds) − 1 bars, one way is fixed, and you collect different pictures one by one. Turning on "at least one of each kind" adds the condition, and the show-all button displays every possible picture and how many there are.