Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools


Strong Composition

How to use
  1. The ● Balls / A Letters switch at the left of the control bar draws every item as the same red ball or the same letter A; bars and gaps look the same in both modes. Learn more about the mode switch
  2. The n stepper sets the number of identical items (3 to 7) and the k stepper the number of bins (2 to 4, never more than nn); each change clears the build and updates C(n−1,k−1)C(n - 1, k - 1) at the top right of the scene. Learn more about adjusting n and k
  3. Step ▶ drops one bar into its gap, ◀ Back undoes one step, ▶ Play builds every composition and stops at the end, ↺ Reset clears the completed section, and Speed sets how fast the bars fly. Learn more about the transport controls
  4. The top right of the scene shows the count C(n−1,k−1)C(n - 1, k - 1) and a status line such as x₁ = 1: 0 / 3. Learn more about getting started
  5. In the items row, bars land only in the dashed drop-zones between items; coloured bands mark the bins and the brackets below read x1,x2,…x_1, x_2, \dots as soon as the bars fix them. Learn more about items and gaps
  6. Under the strip, composition: ( … ) ⇔ chosen gaps: { … } shows the same build in both encodings, and the formula card writes out the full count. Learn more about the composition and gap readouts
  7. The COMPLETED section files each strip in the row of its first-bin count x1x_1, with the count of finished compositions at its right. Learn more about grouping by first-bin count
  8. The right panel adds one row per value of x1x_1, with a counter such as 0 / 3 and the formula for that row; a ✓ marks each finished row. Learn more about the right panel


Press ▶ Play to build all C(n−1, k−1) strong compositions of n identical items into k bins, where every bin must hold at least one item. A bin is a run of consecutive items between two chosen gaps (or before the first / after the last); the count of items in bin i is xᵢ ≥ 1. Each outcome = a choice of k − 1 gap positions out of the n − 1 gaps between adjacent items.
● BallsA Letters
n =5?
k =3?
Speed
C(4, 2) = 6Press Play or Step to beginBARS TO PLACE (k − 1 = 2)ITEMS (n = 5) · GAPS (n − 1 = 4)123411111x₁ = ?x₂ = ?x₃ = ?composition: (?, ?, ?)⇔chosen gaps: {?, ?}Choose k − 1 = 2 gaps out of the n − 1 = 4 gaps between items:C(4, 2) = 4!/(2! · 2!) = 24/(2·2) = 6
Strong compositions (positive parts)
C(n−1, k−1) = C(4, 2)
= 4! / (2! · 2!)
= 24 / (2 · 2)
= 6
Distribute n identical items into k distinct bins, with every bin holding at least one item. Count the solutions to x₁ + x₂ + … + xₖ = n in positive integers (xᵢ ≥ 1). Equivalently: choose k − 1 of the n − 1 gaps between adjacent items to place dividers — no two at the same gap, none at the ends.
Bars land only between items — never at the ends — so "every bin gets at least one" is enforced by the board, not by arithmetic. Learn more about getting started · Adjusting n and k





Key Terms



Key Terms

Strong composition — a distribution of nn identical items into kk distinct bins where every bin must hold at least one item. Equivalently, the number of positive integer solutions to x1+x2+⋯+xk=nx_1 + x_2 + \dots + x_k = n. The count is (n−1k−1)\binom{n - 1}{k - 1}.

Positive parts — the requirement xi≥1x_i \geq 1 for every ii, which distinguishes strong from weak compositions. Empty bins are not allowed.

Gap — the space between two adjacent items in the row. With nn items, there are exactly n−1n - 1 gaps available, and each gap can hold at most one divider.

Divider / bar — the k−1k - 1 vertical bars placed in chosen gaps that split the nn items into kk runs. Two dividers cannot share a gap, and no divider sits at the start or end (those would create empty bins).

Composition tuple (x1,x2,…,xk)(x_1, x_2, \dots, x_k) — the encoded outcome: xix_i is the run length in bin ii, with x1+x2+⋯+xk=nx_1 + x_2 + \dots + x_k = n and each xi≥1x_i \geq 1.

group — the family of strong compositions with the same first-bin count. Group sizes vary as (n−j−1k−2)\binom{n - j - 1}{k - 2} for x1=jx_1 = j, with jj ranging from 11 to n−k+1n - k + 1.

Getting Started

The tool opens with n=5n = 5 identical items and k=3k = 3 bins. The scene splits into three areas:

• A holding row at the top labeled *BARS TO PLACE (k − 1 = K)* showing the k−1k - 1 dividers waiting to be inserted.

• An items row in the middle labeled *ITEMS (n = N) · GAPS (n − 1 = N-1)* — a row of nn identical items with the n−1n - 1 gaps between them numbered 11 through n−1n - 1.

• A completed section below, where every finished composition is filed under the row matching its x1x_1 value.

To run the visualization:

• Press ▶ Play to auto-build all (n−1k−1)\binom{n - 1}{k - 1} strong compositions.

• Press Step ▶ to drop one bar at a time.

• Press ◀ to step backward.

• Adjust the Speed slider.

The header shows the formula C(n−1,k−1)=totalC(n - 1, k - 1) = \text{total} alongside a live status line like *x1=jx_1 = j: kk / size*.
C(4, 2) = 6Press Play or Step to beginBARS TO PLACE (k − 1 = 2)ITEMS (n = 5) · GAPS (n − 1 = 4)123411111x₁ = ?x₂ = ?x₃ = ?composition: (?, ?, ?)⇔chosen gaps: {?, ?}Choose k − 1 = 2 gaps out of n − 1 = 4 gaps between items:C(4, 2) = 4!/(2! · 2!) = 24/(2·2) = 6
(n, k) = (5, 3), idle, frozen

Five items shoulder to shoulder with four dashed drop-zones between them — the only legal landing sites, and the reason no bin can end up empty.

The frozen frame above is the opening position, and the difference from its weak counterpart is written into the geometry: there are no cells for the bars. Five items sit shoulder to shoulder, and the only landing sites are the four dashed drop-zones between them — never before the first item, never after the last.

That single design choice does all the enforcement. A divider that can only land between two items can never leave a bin empty, so the constraint xi≥1x_i \geq 1 needs no checking — it is built into the board.

Items and Gaps

The strip is where the gap-selection encoding plays out. Five things to watch:

• n items (identical red balls or letter A) sit fixed in their cells from the start. The items themselves never move — only the dividers do.

• n − 1 gap drop-zones sit between adjacent items as dashed mini-rectangles, numbered above. These are the only places a divider can land.

• Bin bands highlight runs of consecutive items in alternating colors (blue and amber). Items in bin 1 get one tint, bin 2 the other, bin 3 the first again, and so on.

• Bars arrive from the holding row above with a dotted guide line in the bar's color tracing the trajectory. Each bar lands in a specific gap; the gap's drop-zone outline disappears once filled.

• Brackets below the items mark each bin with a label xi=jx_i = j. Brackets are progressive: each label shows ?? until enough bars land to determine the run length.

When all k−1k - 1 bars are placed, a flash ring pulses around the strip and the composition is filed in the completed grid below.

Notice what's impossible here: a bar cannot sit at position 0 (before item 1) or position nn (after item nn), and two bars cannot share a gap. Both restrictions are exactly what enforces xi≥1x_i \geq 1, as the gap-choice argument spells out.
C(4, 2) = 6x₁ = 1: 1 / 3BARS TO PLACE (k − 1 = 2)ITEMS (n = 5) · GAPS (n − 1 = 4)123411111x₁ = 1x₂ = ?x₃ = ?composition: (1, ?, ?)⇔chosen gaps: {1, ?}Choose k − 1 = 2 gaps out of n − 1 = 4 gaps between items:C(4, 2) = 4!/(2! · 2!) = 24/(2·2) = 6COMPLETED1 / 6x₁ =111111(1, 1, 3)
(5, 3) mid-build, frozen

One bar seated in gap 1, sealing x₁ = 1; the second rides its guide toward gap 3. Bars can never share a gap, so bins never collapse to zero.

The frozen frame above catches the second composition mid-build: one bar already seated in gap 1 — sealing x1=1x_1 = 1 — while the second rides its guide toward gap 3. The readout has hardened to (1,2,?)(1, 2, ?), and two drop-zones remain dashed and available.

Compare this to the weak tool's strip, where bars could land beside each other and collapse a bin to zero. Here adjacency is impossible: every gap holds at most one bar, and every bar has an item on each side. The rule is enforced by the furniture rather than by arithmetic.

Composition and Gap Readouts

Under the items row, two readouts restate the current build in both encodings, joined by ⇔:

• composition: ( … ) — the bin counts (x1,x2,…,xk)(x_1, x_2, \dots, x_k).

• chosen gaps: { … } — the numbers of the gaps that hold a bar.

Both start as question marks — (?,?,?)(?, ?, ?) and {?,?}\{?, ?\} for the default n=5n = 5, k=3k = 3 — and fill in as bars land. In the first build, one Step ▶ gives (1,?,?)⇔{1,?}(1, ?, ?) \Leftrightarrow \{1, ?\}: the first bar in gap 1 seals x1=1x_1 = 1. The second gives (1,1,3)⇔{1,2}(1, 1, 3) \Leftrightarrow \{1, 2\}, and the last bin is known only now, because it runs from the last bar to the end of the row. The same values appear in the brackets under the items.

Below the readouts, a formula card spells out the count for the current nn and kk: Choose k − 1 = 2 gaps out of n − 1 = 4 gaps between items, followed by C(4,2)=4!/(2!⋅2!)=24/(2⋅2)=6C(4, 2) = 4!/(2! \cdot 2!) = 24/(2 \cdot 2) = 6. The card changes only with the n and k steppers; the readouts change with every bar.

The two-way arrow is the gap-choice argument in one line: each set of k−1k - 1 gaps gives exactly one composition, and each composition gives back exactly one set of gaps.

Adjusting n and k

DemoChanging n and k
Step 0 of 5
Two steppers in the control bar control the size:

• n sets the number of identical items. Range 33 to 77.

• k sets the number of bins. Range 22 to 44, with the additional constraint k≤nk \leq n (you can't have more nonempty bins than items).

Common combinations:

• n=3,k=2n = 3, k = 2: (21)=2\binom{2}{1} = 2 compositions: (2,1)(2, 1) and (1,2)(1, 2).

• n=4,k=2n = 4, k = 2: (31)=3\binom{3}{1} = 3 compositions — one bar among the gaps.

• n=5,k=3n = 5, k = 3: (42)=6\binom{4}{2} = 6 compositions — the default configuration.

• n=6,k=3n = 6, k = 3: (52)=10\binom{5}{2} = 10 compositions.

• n=7,k=4n = 7, k = 4: (63)=20\binom{6}{3} = 20 compositions — the largest run on this page.

• n=kn = k: exactly 11 composition — every gap takes a bar.

Reducing nn below the current kk clamps kk down automatically. Changing either value resets the build, refreshes the formula in the header, and rebuilds the completed section into the new set of x1x_1-rows.

Note the symmetry with binomial coefficients: (n−1k−1)=(n−1n−k)\binom{n - 1}{k - 1} = \binom{n - 1}{n - k}. For example (62)=(64)=15\binom{6}{2} = \binom{6}{4} = 15 — the same count interpreted as choosing gap positions or choosing non-divider positions.

Grouping by First-Bin Count

DemoRows by first-bin count
Step 0 of 5
The completed section organizes strong compositions by x1x_1 — the count of items in the first bin. There are n−k+1n - k + 1 rows total (since x1x_1 ranges from 11 to n−k+1n - k + 1, with the cap ensuring the remaining k−1k - 1 bins can each hold at least one item).

When x1=jx_1 = j, the remaining n−jn - j items must form a strong composition of size k−1k - 1:

group size at x1=j=(n−j−1k−2)\text{group size at } x_1 = j = \binom{n - j - 1}{k - 2}


For example with n=5,k=3n = 5, k = 3:

• x1=1x_1 = 1: split 4 items into 2 nonempty bins. (31)=3\binom{3}{1} = 3 compositions.

• x1=2x_1 = 2: split 3 items into 2 nonempty bins. (21)=2\binom{2}{1} = 2 compositions.

• x1=3x_1 = 3: split 2 items into 2 nonempty bins. (11)=1\binom{1}{1} = 1 composition.

Total: 3+2+1=6=(42)3 + 2 + 1 = 6 = \binom{4}{2}.

The decomposition gives a visual proof of ∑j=1n−k+1(n−j−1k−2)=(n−1k−1)\sum_{j=1}^{n-k+1} \binom{n - j - 1}{k - 2} = \binom{n - 1}{k - 1}, a shifted variant of the hockey-stick identity.
C(4, 2) = 6Complete · 6 / 6BARS TO PLACE (k − 1 = 2)ITEMS (n = 5) · GAPS (n − 1 = 4)123411111x₁ = 3x₂ = 1x₃ = 1composition: (3, 1, 1)⇔chosen gaps: {3, 4}Choose k − 1 = 2 gaps out of n − 1 = 4 gaps between items:C(4, 2) = 4!/(2! · 2!) = 24/(2·2) = 6COMPLETED6 / 6x₁ =111111(1, 1, 3)11111(1, 2, 2)11111(1, 3, 1)x₁ =211111(2, 1, 2)11111(2, 2, 1)x₁ =311111(3, 1, 1)
C(4, 2) complete, frozen

Six strips in rows of 3, 2, 1 — a countdown that starts at x₁ = 1, because every other bin is owed an item of its own.

The frozen frame above is that example completed: six strips in rows of 33, 22, 11. The countdown is shorter than the weak tool's — it starts at x1=1x_1 = 1 rather than 00, and stops at x1=3x_1 = 3 rather than 55, because the other bins each demand an item of their own.

Those missing rows are the whole difference between the two scenarios. Weak compositions of 5 into 3 number (72)=21\binom{7}{2} = 21; strong ones number 66. The gap between them is the price of the phrase at least one.

Two Bins, One Divider

Set k=2k = 2 and the whole scenario collapses to a single question: *where does the one bar go?* With n=5n = 5 items there are 44 gaps, so (41)=4\binom{4}{1} = 4 compositions — (1,4),(2,3),(3,2),(4,1)(1,4), (2,3), (3,2), (4,1).

Every composition is named by its bar's gap number, and the tuple is always (j,n−j)(j, n - j) for the gap jj chosen. Nothing is hidden: the count of compositions equals the count of gaps.

Note that (0,5)(0, 5) and (5,0)(5, 0) are missing, and their absence is the point — those would need a bar outside the row, which the drop-zones do not offer.
C(4, 1) = 4Complete · 4 / 4BARS TO PLACE (k − 1 = 1)ITEMS (n = 5) · GAPS (n − 1 = 4)123411111x₁ = 4x₂ = 1composition: (4, 1)⇔chosen gaps: {4}Choose k − 1 = 1 gaps out of n − 1 = 4 gaps between items:C(4, 1) = 4!/(1! · 3!) = 24/(1·6) = 4COMPLETED4 / 4x₁ =111111(1, 4)x₁ =211111(2, 3)x₁ =311111(3, 2)x₁ =411111(4, 1)
C(4, 1) complete, frozen

One bar, four gaps, four compositions: each card is named by the gap its divider occupies, and the tuple is always (j, n − j).

This is the cleanest place to feel why the strong count uses n−1n - 1 rather than n+1n + 1. The weak version of the same question allows the bar to sit at either end as well, giving (61)=6\binom{6}{1} = 6 — the same four splits plus the two lopsided ones with an empty bin.

Two bins also connects to a familiar object: splitting a row of nn items into a nonempty prefix and a nonempty suffix is exactly choosing a cut point, and there are n−1n - 1 of those. Many "in how many ways can a sequence be broken" questions reduce to this count.

Twenty Ways: The Largest Run

The tool's largest setting: n=7n = 7 items, k=4k = 4 bins, so three bars choose among six gaps — (63)=20\binom{6}{3} = 20 strong compositions.

The four x1x_1-rows hold 10,6,3,110, 6, 3, 1 cards. Each is itself a complete smaller run: after the first bin takes jj items, the remainder is a strong composition of 7−j7 - j into 33 parts, and those counts (52),(42),(32),(22)\binom{5}{2}, \binom{4}{2}, \binom{3}{2}, \binom{2}{2} are the triangular numbers walking down.

Twenty is also the middle of Pascal's sixth row — (63)\binom{6}{3} is the largest binomial coefficient available at that level, which makes this the most crowded strip the tool can draw.
C(6, 3) = 20Complete · 20 / 20BARS TO PLACE (k − 1 = 3)ITEMS (n = 7) · GAPS (n − 1 = 6)1234561111111x₁ = 4x₂ = 1x₃ = 1x₄ = 1composition: (4, 1, 1, 1)⇔chosen gaps: {4, 5, 6}Choose k − 1 = 3 gaps out of n − 1 = 6 gaps between items:C(6, 3) = 6!/(3! · 3!) = 720/(6·6) = 20COMPLETED20 / 20x₁ =11111111(1, 1, 1, 4)1111111(1, 1, 2, 3)1111111(1, 1, 3, 2)1111111(1, 1, 4, 1)1111111(1, 2, 1, 3)1111111(1, 2, 2, 2)1111111(1, 2, 3, 1)1111111(1, 3, 1, 2)1111111(1, 3, 2, 1)1111111(1, 4, 1, 1)x₁ =21111111(2, 1, 1, 3)1111111(2, 1, 2, 2)1111111(2, 1, 3, 1)1111111(2, 2, 1, 2)1111111(2, 2, 2, 1)1111111(2, 3, 1, 1)x₁ =31111111(3, 1, 1, 2)1111111(3, 1, 2, 1)1111111(3, 2, 1, 1)x₁ =41111111(4, 1, 1, 1)
C(6, 3) complete, frozen

Twenty compositions in rows of 10, 6, 3, 1 — the centre of Pascal’s sixth row, the most crowded strip the tool can draw.

The central-binomial position is not a coincidence of the caps: for fixed nn, the strong-composition count (n−1k−1)\binom{n-1}{k-1} peaks when k−1k - 1 is half of n−1n - 1 — bins that are neither too few nor too many. Splitting seven items into four bins is the most "uncertain" question this tool can ask.

Summing across all kk for n=7n = 7 would give 26=642^6 = 64 compositions in total, of which these twenty are the four-bin share — the largest single slice, as related concepts notes.

When k = n: The Forced Composition

Push kk up to nn and the freedom vanishes: with as many bins as items and every bin demanding at least one, each bin must hold exactly one. The count bottoms out at

(n−1n−1)=1\binom{n - 1}{n - 1} = 1


and the single composition is (1,1,…,1)(1, 1, \dots, 1).

The picture makes the reasoning unnecessary: there are n−1n - 1 gaps and n−1n - 1 bars, so every gap takes a bar. Nothing is left to choose — the completed section holds one card, with every item fenced off alone.

This is also the boundary the k≤nk \leq n constraint protects. Asking for k>nk > n nonempty bins is impossible, and the formula agrees: (n−1k−1)=0\binom{n-1}{k-1} = 0 when k−1>n−1k - 1 > n - 1.
C(3, 3) = 1Complete · 1 / 1BARS TO PLACE (k − 1 = 3)ITEMS (n = 4) · GAPS (n − 1 = 3)1231111x₁ = 1x₂ = 1x₃ = 1x₄ = 1composition: (1, 1, 1, 1)⇔chosen gaps: {1, 2, 3}Choose k − 1 = 3 gaps out of n − 1 = 3 gaps between items:C(3, 3) = 3!/(3! · 0!) = 6/(6·1) = 1COMPLETED1 / 1x₁ =11111(1, 1, 1, 1)
k = n complete, frozen

Every gap takes a bar and every bin holds exactly one item: a single card, the forced composition (1, 1, 1, 1).

Both extremes of the stepper now have names: at k = 2 one bar roams freely among many gaps, and here every gap is occupied. Between them the count rises and falls along a row of Pascal's triangle, peaking near the middle as the largest run shows.

The zero case beyond the boundary is worth stating because word problems produce it constantly: *"distribute 4 identical prizes among 6 people, everyone getting at least one"* has no solutions at all, and the binomial coefficient reports that honestly rather than erroring.

Transport Controls

DemoStep, file, back
Step 0 of 5
The control bar offers four transport buttons plus a speed slider:

• ◀ (Step back) — walks the animation one step backward.

• Step ▶ (Step forward) — drops one bar into its chosen gap. Stop after each step to read the partial composition; un-marked bins show ?? in their brackets.

• ▶ Play / ⏸ Pause — runs continuously until all (n−1k−1)\binom{n - 1}{k - 1} strong compositions are built, then auto-pauses.

• ↺ Reset — clears the completed section and starts over.

The Speed slider controls how fast play advances. At slower speeds you can clearly see each bar travel from the holding row into a specific gap drop-zone, and watch the bin brackets update from ?? to the actual run length.

Mode Switch

DemoBalls and letters
Step 0 of 4
The Mode switch at the start of the control bar toggles how the identical items are rendered:

• Balls mode (default) — items appear as red circles. All circles are identical because the items themselves are indistinguishable. Best for the classical visual of dividing a row of dots.

• Letters mode — items appear as the letter A. Same identicality applies — every item shows the same letter. Best when reading compositions algebraically and emphasizing that the items are interchangeable.

The encoding is consistent across the items row, the mini cards in the completed grid, and the right-panel narration. Bars and gap drop-zones are unaffected — they always render as accent-colored bars and dashed outlines regardless of mode.

Right Panel and Progress

The right panel narrates the build as it unfolds, anchored by the header *Strong compositions (positive parts)* with the formula across multiple lines and a reminder that this counts positive integer solutions to x1+x2+⋯+xk=nx_1 + x_2 + \dots + x_k = n via choosing k−1k - 1 of n−1n - 1 gaps.

A StepRow is added for each x₁-group as soon as a composition in that group starts or completes. Each StepRow shows:

• The first bin count as a label — *First bin: x1=jx_1 = j*.

• A progress counter k/(n−j−1k−2)k / \binom{n - j - 1}{k - 2} tracking how many compositions in this group have completed.

• A short narration of the structure: *When the first bin holds jj items (x1=jx_1 = j), the remaining n−jn - j items are split among the other k−1k - 1 bins (each ≥1\geq 1), giving (n−j−1k−2)\binom{n - j - 1}{k - 2} outcomes.* Edge cases get tailored phrasing: x1=1x_1 = 1 describes the minimum first-bin case; x1=n−k+1x_1 = n - k + 1 describes the maximum where the other bins each hold exactly 11.

When all groups complete, every StepRow shows done with a checkmark, and the counter reaches *total / total*.

What Is a Strong Composition

A strong composition of nn into kk parts is an ordered tuple (x1,x2,…,xk)(x_1, x_2, \dots, x_k) of positive integers summing to nn:

x1+x2+⋯+xk=n,xi≥1x_1 + x_2 + \dots + x_k = n, \quad x_i \geq 1


The word strong (sometimes simply composition) distinguishes this from a weak composition, which allows zero parts. Every strong composition is also a weak composition with no zeros.

The count of strong compositions is:

(n−1k−1)\binom{n - 1}{k - 1}


The total number of compositions of nn (with any number of positive parts) is 2n−12^{n-1}, since each of the n−1n - 1 gaps independently has or does not have a bar.

Examples:

• Ways to split 1010 identical pencils among 33 kids so each gets at least one: (92)=36\binom{9}{2} = 36.

• Number of positive integer solutions to a+b+c+d=10a + b + c + d = 10: (93)=84\binom{9}{3} = 84.

• Compositions of 55 into exactly 33 parts: (42)=6\binom{4}{2} = 6, namely (3,1,1),(1,3,1),(1,1,3),(2,2,1),(2,1,2),(1,2,2)(3,1,1), (1,3,1), (1,1,3), (2,2,1), (2,1,2), (1,2,2).

• Total compositions of 44: 23=82^3 = 8 across all values of kk.

On this page the idea runs live: from the opening row of items, bars drop into the gaps between them, results group into x₁-rows, and the n and k steppers run the count from the single-divider case through twenty ways to the forced composition at k=nk = n.

For deeper coverage of strong compositions, see the strong composition section on the combinations theory page.

The Gap-Choice Argument

The classical proof maps strong compositions to a simple gap-selection problem.

Arrange the nn items in a row. Between each pair of adjacent items there is a gap, giving n−1n - 1 gaps total. The gaps are the only candidate sites for dividers — putting a divider before the first item or after the last would create an empty bin, which strong compositions don't allow.

A strong composition is determined by which k−1k - 1 gaps hold dividers. Choose any k−1k - 1 of the n−1n - 1 gaps to receive a bar. The bars partition the row into kk runs of consecutive items; the iith run is bin ii, and its length is xix_i. Every xi≥1x_i \geq 1 automatically because there's at least one item between any two adjacent bars (and at the ends).

Count the selections. Choosing k−1k - 1 items from a set of n−1n - 1 is a binomial coefficient:

(n−1k−1)\binom{n - 1}{k - 1}


This is exactly the visual the tool implements. The nn items sit fixed; the n−1n - 1 gaps appear as dashed drop-zones; the user (or the auto-play loop) drops k−1k - 1 bars into chosen gaps; the bin brackets convert the chosen-gap set back into the tuple (x1,…,xk)(x_1, \dots, x_k).

Connection to weak compositions. Set yi=xi−1≥0y_i = x_i - 1 \geq 0. Then y1+⋯+yk=n−ky_1 + \dots + y_k = n - k is a weak composition, counted by (n−k+k−1k−1)=(n−1k−1)\binom{n - k + k - 1}{k - 1} = \binom{n - 1}{k - 1}. Same formula, derived two ways.