Permutations with repetition
Count ordered sequences when symbols may repeat: 5 symbols across 3 positions give 125 possibilities, 5^3, the same product rule behind codes and password spaces. Exact even for huge results. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Number of distinct symbols
- 5
- Resistance (Ω)
- 3
- Value
- 125
- Quantity
- 125
Permutations with repetition answer a simple counting question: if you have n distinct symbols and you form ordered sequences of length r where the same symbol may appear more than once, how many sequences exist? The product rule multiplies n choices at each of the r positions, so the total is exactly n raised to the power r. That formula appears in password spaces, PIN codes, colorings of fixed-length strings, sampling with replacement, and countless discrete-math homework problems where the answer must be an exact integer rather than a floating-point approximation. This capability accepts positive integer n (the alphabet size) and non-negative integer r (the sequence length) and returns the exact count as a decimal string computed with BigInt arithmetic, so values far beyond ordinary safe-integer limits stay correct digit for digit. Inputs with n below one or a negative r are rejected with a clear validation error instead of a silent wrong answer.
How permutations with repetition are defined
An ordered selection of r positions from n symbols with repetition allowed is any sequence s1, s2, …, sr where each si belongs to a fixed set of size n. Because order matters and symbols may repeat, the first position has n options, the second again has n options, and so on for every position through r. The fundamental counting principle multiplies those independent choices into n × n × … × n, which is n to the power r.
When r equals zero there is exactly one empty sequence, matching the algebraic convention that any positive n raised to the power zero equals one. This is different from permutations without repetition, which forbid reuse and yield the falling factorial n × (n − 1) × … × (n − r + 1), and different from combinations, which ignore order. Classic textbook checks include two symbols of length three giving eight sequences, five symbols of length two giving twenty-five sequences, and ten symbols of length zero giving one.
This implementation never uses floating-point power, approximate logarithms, or sampling: it computes the exact integer power with binary BigInt exponentiation so every digit is correct. The path is fully deterministic—no random seeds, no clocks, no network, and no model drift—so the same n and r always yield the same string.
Where n to the r counting shows up in real work
Security and product teams estimate password or PIN spaces by treating each character position as choosing from an alphabet of size n for length r, which is exactly the permutations-with-repetition count n to the r; exact integers help when comparing scheme strength without log approximations.
Programming contests and discrete-mathematics courses constantly ask for the number of words of length r over an alphabet of n letters, for colorings of r beads with n colors when order matters and colors may repeat, or for functions from a set of size r into a set of size n—all of which equal n raised to r. Data and sampling pipelines that model with-replacement ordered draws need the same product when sizing sample spaces or validating Monte Carlo setups against an analytic total.
Educators and interview prep often show a short table of small n and r values; computing the count in one call keeps interactive demos aligned with textbooks and answer keys. If you later need permutations without repetition, combinations with or without repetition, or listing of the actual tuples rather than the count, treat those as separate search intents rather than overloading this landing.
What you can do with it
Password and PIN space size
Compute exact n^r alphabet spaces for fixed-length codes and compare scheme sizes without floating-point log approximations.
Sampling and function counts
Size ordered with-replacement sample spaces and count functions from r positions into n symbols for design reviews.
FAQ
What are permutations with repetition?
They are ordered sequences of length r drawn from n symbols where the same symbol may appear more than once. The total count is exactly n raised to the power r.
How is this different from permutations without repetition?
Without repetition each symbol may be used at most once, giving the falling factorial n×(n−1)×…×(n−r+1). With repetition, reuse is allowed, so the count is n^r.
Why is the count a string instead of a number?
Powers grow past JavaScript safe integers quickly. Decimal strings keep every digit exact for large n^r values.
What does it cost?
The browser tool is free and runs locally.
What happens if the length is zero?
You get 1, because there is exactly one empty sequence, just as any positive number raised to the power zero equals one. The number of symbols must still be at least 1.
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/combo/permutations-with-repetition \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":5,"r":3}'const res = await fetch("https://api.kit.forhosting.com/combo/permutations-with-repetition", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 5,
"r": 3
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/combo/permutations-with-repetition",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 5,
"r": 3
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/combo/permutations-with-repetition", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":5,"r":3}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":5,"r":3}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/combo/permutations-with-repetition", 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": 5,
"r": 3
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "combo.permutations_with_repetition",
"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.
Limits
min_n | 1 |
max_n | 10000 |
min_r | 0 |
max_r | 10000 |
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
The free browser tool and the paid API share one pure function, so classroom demos and automated pipelines never diverge on the same pair.
How permutations with repetition are defined
Declared bounds keep n between one and ten thousand and r between zero and ten thousand so worst-case latency stays suitable for a free in-browser tool and a lightweight Worker path while still covering contest, classroom, and pipeline needs for exact large counts.
What you send and what you get back
The symbol count n must be an integer from one through ten thousand inclusive; the length r must be an integer from zero through ten thousand inclusive. Error messages name the offending field and the rule that failed so form clients and scripts can correct the input without guessing. On success the response always includes the normalized n and r, count and value as the same exact decimal string for n to the power r, and a short formula string such as five caret three for display. Provide a required integer n under the field n (aliases symbols or alphabet) and a required integer r under the field r (aliases length or k). Missing fields, non-integers, decimals, n below one, and any negative r are rejected with invalid_input and are not charged. Example checks: n equals two and r equals three yields count eight; n equals five and r equals two yields count twenty-five; n equals ten and r equals zero yields count one; n equals one and r equals any valid length yields count one; n equals zero yields invalid_input because the alphabet size is below one; r equals negative one yields invalid_input. Pricing for successful API calls is the published base of $0.002 per item; validation failures do not consume prepaid balance.
Where n to the r counting shows up in real work
Because this capability is a pure parse engine, API pricing is the published base of $0.002 per successful item and failed validation does not consume balance.
Integration use cases
Contest and homework fixtures
Generate exact ordered-with-repetition counts for olympiad problems, discrete-math exercises, and automated answer keys.
Technical questions
What happens if n is below 1 or r is negative?
The request fails with invalid_input. This calculator requires n ≥ 1 and r ≥ 0; invalid bounds are rejected and not charged.