List all ordered compositions of an integer
The number 4 has 8 compositions, from 1+1+1+1 to 4 itself, and this tool lists every one of them in a fixed order with the count beside it. Enter any n from 1 to 16. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- N
- 4
- Quantity
- 8
An ordered composition of a positive integer n is a way of writing n as a sum of positive integers where the order of the summands matters: 1+2 and 2+1 are different compositions of 3, and there are always exactly 2 to the power of n minus one compositions in total.
What ordered compositions are and how they differ from partitions
In number theory and combinatorics, a composition of n is an ordered sequence of positive integers that add up to n. Unlike integer partitions, where only the multiset of parts matters and 1+2 is identified with 2+1, compositions treat every ordering as a distinct object. For any n at least one there are exactly two to the power of n minus one compositions: each composition corresponds to placing or omitting a separator between consecutive units in a line of n ones.
Textbooks use compositions when order encodes sequence, ranking, or staged allocation—for example successive block sizes in a schedule, run lengths in a binary string, or step sizes along a path that must cover exactly n units. Students often confuse the two families because both answer “how can n be written as a sum,” yet only compositions care about left-to-right order.
Returning the full ordered list makes that distinction concrete: you see every rearrangement, not a canonical sorted representative, and the count field should match the closed formula so you can spot an incomplete hand enumeration immediately.
How the capability enumerates compositions and when it refuses
The engine builds every composition by recursive first-part expansion: for remaining sum r it tries every part size k from one through r, prepends or appends k to the growing prefix, and continues until the remainder is zero, at which point the completed sequence is recorded. That walk yields a stable, deterministic order—identical requests always produce the same array of arrays—without relying on clocks, randomness, or network state.
The response reports n itself, the compositions array, and count equal to the length of that array (which is always two to the power of n minus one for a valid n). Missing, non-integer, or malformed n fields are rejected the same way and are never charged.
Where to use the list and what it costs
Typical placements include verifying student answers that list compositions of a given n, generating exhaustive test cases for functions that accept ordered part sequences, exploring combinatorial identities that count compositions with restricted part sizes by post-filtering the full list, and documenting staging options when a budget of n units can be split into ordered phases.
Keep n inside the documented bounds so the response stays manageable; if you only need the count, you can still use this tool for small n or apply the closed formula two to the power of n minus one outside the tool for larger theoretical work. The browser path runs locally and needs no account. Treat the returned count as authoritative for the listed arrays rather than recomputing length in client code that might drift from this contract.
What you can do with it
Homework and contest verification
Compare a student’s ordered list of compositions for a given n against the canonical full enumeration and count instead of grading partial hand trees.
Combinatorics exploration and teaching demos
Show live how order distinguishes compositions from partitions, and confirm that the returned count always equals two to the power of n minus one.
FAQ
How do I list all ordered compositions of an integer?
The response includes compositions as arrays of parts, plus count.
What is the difference between a composition and a partition?
Compositions treat order as significant (1+2 differs from 2+1). Partitions ignore order and keep only the multiset of parts.
How many compositions does 4 have?
It has 8: 1+1+1+1, 1+1+2, 1+2+1, 1+3, 2+1+1, 2+2, 3+1 and 4. That matches 2^(n-1), so a hand-written list for 4 with fewer entries is missing some.
Why can n only go up to 16?
The list doubles every time n grows by one, so large values would produce an enormous answer. Up to 16 the full list stays practical to read and check; if you only need how many there are, the formula 2^(n-1) is enough.
Is the list always in the same order?
Yes. The same n always returns the same list in the same order, built by trying each possible first part from the smallest to the largest, so you can compare answers line by line.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/numth/compositions-list \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":4}'const res = await fetch("https://api.kit.forhosting.com/numth/compositions-list", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 4
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/numth/compositions-list",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 4
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/numth/compositions-list", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":4}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":4}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/numth/compositions-list", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"n": 4
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "numth.compositions_list",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
How the capability enumerates compositions and when it refuses
You send a JSON body with a single required field n, a positive integer at least one and at most sixteen. Values below one fail with invalid_input because zero and negatives are not positive integers under the usual composition definition. Values above the published ceiling also fail with invalid_input: the list size doubles with each increment of n, so unbounded enumeration would explode response size and Worker CPU; the documented maximum keeps full listing practical for browser and API use alike.
Where to use the list and what it costs
Use the free browser tool when you want a quick visual check for a small n, or call the API when a script, gradebook, generator, or research notebook must resolve many values the same way every time. API usage draws from prepaid KIT balance at the published $0.002 base price per successful request; failed validation does not consume balance.
Integration use cases
Exhaustive test-fixture generation
Feed small n values into the API and use every composition as an input case for functions that process ordered positive-integer sequences summing to a budget.
Technical questions
Why does the tool reject large n?
The number of compositions is 2^(n-1). Above the published maximum the full list is too large to enumerate safely in a single request, so the call fails with invalid_input.
Is the integer compositions list free?
The browser widget is free and runs locally. API calls use prepaid KIT balance at the published $0.002 base price; invalid input is not charged.
Is the result always the same for the same n?
Yes. The algorithm is pure recursive enumeration with no randomness or timestamps, so identical inputs produce identical JSON.