Integer Composition Generator
How many ways can you write 5 as a sum of positive whole numbers, if order matters? The answer is exactly 16, and it is 2 to the power of 4 — because between the five units there are four gaps, and each is either a break or not. That argument makes the count obvious once you see it, and it is a good example of a bijection doing the work a formula would otherwise have to.
What this generator does
Lists every ordered sum of positive whole numbers reaching the total, breaks the count down by how many parts each uses, and compares the total against 2 to the power of one less than the number.
How to use this tool
- Choose the number to split.
- Predict the count before generating.
- Compare the enumeration against two to the power of one less.
- Show the full list to see them all.
Understanding the controls
- The number to split
- Between 2 and 9. Nine has 256 compositions, which is the practical limit for listing them.
- Seed
- Chooses which composition is shown as the example.
- Show the full list
- Lists every composition rather than just the count and one example.
Common use cases
- Counting exercises where the gap argument makes the formula obvious
- Showing the difference between compositions and partitions
- Test data for anything consuming ordered decompositions
- Teaching bijective proofs concretely
- Picking a specific composition from a seed
How this generator works
Enumeration builds each composition by choosing the first part and recursing on the remainder, which produces each ordered sum exactly once. The check requires the count to equal 2 to the power of one less than the total — the gap argument — and every composition to sum correctly with no repeats.
Randomness and fairness
Only which composition is shown as the example is random; the enumeration and the count are fixed for a given total. Seeded runs pick the same example and are therefore explicitly not cryptographically secure.
For how randomness is produced across the whole site, see how Generate Random works.
Limitations and good to know
- Nine is the ceiling, since the count doubles with every increment.
- Compositions only — partitions, where order does not matter, are a much harder counting problem with no simple formula.
- Parts must be positive, so zero parts never appear.
- Compositions are listed in enumeration order rather than sorted.
- Nothing is retained after the visit; seed it to return to one composition.
Privacy and your data
Compositions are enumerated in your browser. Nothing about them or your seed is transmitted.
Related generators
- Set Partition GeneratorEvery way of splitting a small set into unlabelled groups, counted against the Bell number and broken down by group count.
- Derangement GeneratorPermutations that leave nothing in its original place, counted by enumeration and by recurrence and required to agree.
- Permutation and Combination CalculatornPr and nCr side by side, exactly, with the difference between them worked through rather than assumed.
- Balanced Bracket GeneratorEvery balanced bracket sequence of a given size, counted against the Catalan numbers and each checked by the running-depth rule.