Press ▶ Play to build all nr arrangements, or Step ▶ to advance one ball at a time. Each of r positions can be any of n items — repetition allowed.
● BallsA Letters
n =3?
r =2?
Speed
Permutations with repetition
32 = 3 × 3 = 9
Choose r items from n, with order and repetition allowed — each of r positions is filled independently from the full pool of n. Each step builds the family of arrangements whose first item is fixed.
Permutation with repetition — an ordered arrangement of r items chosen from a pool of n distinct items, with each position filled independently and reuse allowed. The count is nr.
$n^r$ — the number of arrangements: n choices for each of r positions, multiplied together. Equivalently, the number of length-r sequences (tuples) over an alphabet of size n.
Unlimited supply — every item in the source set is available for every position, every time. Using an item in one slot does not remove it from the source.
Position — a slot in the arrangement, numbered #1 through #r from left to right in the build area.
First-item group — the family of arrangements that share the same item in position #1. There are n such groups, each containing nr−1 arrangements, since the remaining r−1 positions can each be any of n items.
Tuple — a synonym for an ordered r-element sequence with repetition allowed. The output of a Cartesian product of r copies of the source set.
Getting Started
The tool opens with n=3 and r=2, ready to build. The scene splits into three areas:
• A source row at the top showing the n available items, labeled *SOURCE (n = N) — UNLIMITED SUPPLY*.
• A build area in the middle with r slots labeled #1 through #r.
• A completed section below, where every finished arrangement is filed under the row matching its first item.
To run the visualization:
• Press ▶ Play to auto-build all nr arrangements.
• Press Step ▶ to advance one ball at a time.
• Press ◀ to step backward through the animation.
• Adjust the Speed slider to control how fast play advances.
The header shows the formula nr=total alongside a live status line such as *Step X (item name): k / nr−1* while building, or *Complete · total / total* when done.
The Build Area
The build area is where one arrangement at a time is constructed. The label reads *BUILD AREA (r = R)* with the current r.
What to watch:
• Empty slot outlines with dashed borders, labeled #1,#2,…,#r from left to right.
• When a ball is in flight from the source row to a slot, a dotted guide line in that ball's color traces the trajectory.
• Each ball lands in its assigned slot and stays put until the arrangement completes.
• The source row never dims. This is the visual signature of repetition: even after an item is used, every copy of it remains fully bright in the source — because the supply is unlimited and the same item can be picked again for the next slot.
• When all r slots are filled, a flash ring briefly pulses around the build area. The completed arrangement is then copied to the appropriate first-item row in the completed section below.
Adjusting n and r
Two steppers in the control bar control the size:
• n sets the size of the source pool — the number of distinct options available at every position.
• r sets the number of positions to fill, capped per n to keep nr animation-manageable.
The r caps are:
• n=3: maximum r=4, giving 34=81 arrangements.
• n=4: maximum r=3, giving 43=64 arrangements.
• n=5: maximum r=3, giving 53=125 arrangements.
Common combinations:
• n=3,r=2: 32=9 arrangements.
• n=3,r=3: 33=27 arrangements.
• n=4,r=2: 42=16 arrangements.
Reducing n below the current r may also clamp r down automatically when the new n allows a smaller maximum. Changing either value resets the build and refreshes the formula in the header.
Grouping by First Item
The completed section organizes arrangements into first-item groups — every arrangement starting with the same item appears in the same row.
There are exactly n groups (one per item in the source) and each group holds exactly nr−1 arrangements. So the total is:
n×nr−1=nr
This is the visual proof of the nr formula. Pick any item for position #1: n choices. For each choice, the remaining r−1 positions can each independently be any of n items: nr−1 ways. Multiply.
Each group row in the completed area has:
• A tinted background in a faint version of the group's color.
• A colored accent stripe on the left edge.
• A left-side avatar showing the first item — a colored circle with the item's number in balls mode, or the letter in letters mode.
• Mini arrangement cards, each one a full sequence of r items starting with that first item, possibly including repetitions of that item or any other.
Transport Controls
The control bar offers four transport buttons plus a speed slider:
• ◀ (Step back) — walks the animation one step backward. Useful for re-examining a single arrangement or pausing mid-build.
• Step ▶ (Step forward) — advances one ball into one slot. Stop after each step to read the partial arrangement.
• ▶ Play / ⏸ Pause — runs the animation continuously until all nr arrangements are built, then auto-pauses.
• ↺ Reset — clears the completed section and starts over from the first arrangement.
The Speed slider controls how fast play advances. At higher speeds the fly and land timings shrink proportionally; at slower speeds you can clearly see each ball travel from source to slot and follow the dotted guide line in detail.
Mode Switch
The Mode switch at the start of the control bar toggles how each item is rendered:
• Balls mode (default) — items appear as colored circles. The first-item avatar in each completed group is a circle with the item's number. Best for tracking position and group membership visually, and for spotting repeated colors within an arrangement at a glance.
• Letters mode — items appear with letter labels (A, B, C, …). The first-item avatar in each completed group is just the letter, colored to match. Best for reading off the sequence in each arrangement and matching it to algebraic notation like (A,A,C) where repetition is explicit.
The encoding is consistent across the source row, the build slots, the flying ball, every mini card in the completed grid, and the right-panel narration. Switching modes mid-animation is safe — the build state preserves; only the rendering changes.
Right Panel and Progress
The right panel narrates the build as it unfolds, anchored by the header *Permutations with repetition* with the full formula nr=n×n×⋯=total.
A StepRow is added for each first-item group as soon as an arrangement in that group starts building or completes. Each StepRow shows:
• The first item as a chip plus its name — for instance, *First item: A*.
• A progress counter like k/nr−1 tracking how many arrangements in this group have completed.
• A short narration of the structure: *Position 1 is locked to A. The remaining r−1 positions are each filled from A, B, or C (repetition allowed) in n×n×⋯=M ways.* When r=1 the narration adjusts: with only one position, the outcome is just the first item alone.
When all groups complete, every StepRow shows *done* with a checkmark, and the counter reaches *total / total*.
What Is a Permutation with Repetition
A permutation with repetition is an ordered arrangement of r items drawn from a pool of n distinct items, where each position is filled independently and the same item can be reused as many times as needed. The number of such arrangements is:
nr
This is the same as the number of length-r sequences over an alphabet of size n, sometimes called r-tuples or words of length r.
Examples:
• Number of 4-digit PINs from digits 0–9: 104=10,000 codes.
• Number of 3-letter strings over the English alphabet: 263=17,576 strings.
• Outcomes of rolling a 6-sided die 5 times in order: 65=7,776 sequences.
• Binary strings of length 8: 28=256 strings.
The permutation with repetition is the right model whenever positions are filled independently from a fixed pool and reuse is allowed — codes, passwords, function inputs, multiple rolls of the same die.
For deeper coverage, see the permutation with repetition section on the permutations theory page.
Deriving n^r
Apply the multiplication principle of counting one position at a time. The key difference from the no-repetition case is that the count of available options does not shrink between positions:
• Position $\#1$: any of the n items. n choices.
• Position $\#2$: still any of the n items — the previous pick was returned to the pool. n choices.
• Position $\#3$: again n choices.
• …
• Position $\#r$: n choices.
Multiply r identical factors:
n×n×n×⋯×n=nr
The tool visualizes the equivalent factoring: fix the first item (n ways), then fill the remaining r−1 slots independently from the same pool (nr−1 ways). Every row in the completed section is one of those n first-item families, and within each family the leftover positions explore every possible r−1 tuple over the full pool — repetitions of the first item explicitly included.
Counts grow geometrically: 33=27, 34=81, 35=243. Doubling r squares the count.
Related Concepts
Partial permutation without repetition — pick and arrange r items from n distinct items with no reuse. Formula n!/(n−r)!, always smaller than nr for r>1.
Full permutation — every item used exactly once. Special case of partial permutation with r=n, formula n!.
Permutation with identical items — distinct arrangements of a multiset where some items are indistinguishable. Formula n!/(k1!⋅k2!⋯).
Circular permutation — arrange items around a circle where rotations are identical. Formula (n−1)!.
Combination with repetition — the unordered companion of the permutation with repetition. Counts multisets of size r from n types, formula (rn+r−1).
Multiplication principle — the foundational counting rule behind nr. With r independent positions and n options for each, the total is the product of all r factors.
Cartesian product — the set-theoretic name for the collection of r-tuples this tool enumerates: {1,…,n}r.
Combinatorics calculator — to compute nr for arbitrary n and r, see the permutation with repetition calculator.