Kaprekar's Routine
Sort the digits descending and ascending, subtract, repeat. 4-digit inputs converge to 6174; 3-digit inputs to 495. Other lengths settle into a fixed point or short cycle — try it.
What do these numbers and charts mean?
The routine, in one sentence
Pad the number to N digits, sort the digits descending (call it A) and ascending (B), and replace the number with A − B. Repeat. The sequence of values produced is the trajectory; where it ends up is the terminal.
Per-run statistics
Steps — how many Kaprekar steps the routine took. For inputs that converge (e.g. 4-digit), this is the number of steps to reach the fixed point. For inputs that fall into a cycle, this is how many steps you took to enter the cycle (once you're in, you loop forever).
Unique values — how many distinct numbers appeared in the trajectory, counting the start. For convergent runs this equals steps + 1. For cycles it's smaller, because cycle members repeat.
Max reached / Min reached — the largest and smallest numbers seen during the routine. The trajectory chart visualises how the value moves between these.
Digit-sum range — the smallest and largest digit sum across all values in the trajectory. Notice: after the very first step, every digit sum is a multiple of 9 (see the invariant below).
Terminal — the end state. Either a fixed point (a number that maps to itself, like 6174 or 495) or a k-cycle (a loop of k distinct numbers the routine repeats forever).
Width — the number of digits the routine is operating on, including leading zeros. The width changes the behavior: 52 as 2 digits enters a 5-cycle, while 0052 as 4 digits converges to 6174.
All step diffs ÷ 9 — a mathematical invariant of the routine, not a measurement.
Charts
Value trajectory — the actual value at each step. Convergent runs settle to a flat line at the fixed point; cycles oscillate between the cycle members forever (the green dot marks where the terminal begins).
Digit sum chart — the digit sum at each step, with dashed horizontal lines at every multiple of 9. Because of the divisibility invariant, after step 1 every point lands exactly on a dashed line. The starting point may not.
Population analysis (widths ≤ 6)
This runs the Kaprekar routine on every N-digit starting value (all 10N of them, including leading-zero forms like 0052) and aggregates the results.
Histogram — steps to terminal — the x-axis is "how many steps until this starting value reached its terminal", the y-axis is "how many starting values fell in that bucket". Bucket 0 holds the terminals themselves (fixed points and cycle members). Your input's bucket is highlighted in amber.
Terminal table — one row per distinct end state across all starts. Fixed rows are single self-mapping numbers; cycle rows are loops the routine repeats forever. The Share column shows what fraction of all N-digit starts eventually ends there.
Max steps to terminal — the worst case across every start: the slowest-converging value. For 4-digit inputs this is exactly 7 — the famous Kaprekar bound.
What to look for at each width
2 digits: no fixed point besides 00. Every non-trivial start funnels into the 5-cycle 09 → 27 → 45 → 63 → 81 → 09.
3 digits: 99% of starts converge to 495 in ≤ 6 steps. The other 1% are the ten all-same-digit values, which collapse to 000.
4 digits: the classic case. 99.9% of starts reach 6174, the original Kaprekar's constant, in ≤ 7 steps.
5 digits: no fixed point exists. Starts split among three different cycles — the famous "Kaprekar's constant doesn't generalize" result.
6 digits: two distinct fixed points coexist (549945 and 631764) along with a 7-cycle, so the answer depends on where you start.