Kaprekar's Routine
Run Kaprekar's routine: take a number, sort its digits descending (call it K₁) and ascending (K₂), subtract K₂ from K₁ to get a new number, and repeat. For 4-digit numbers (not all the same digit) this always converges to 6174 — the famous Kaprekar constant — in at most 7 steps, no matter where you start. For 3-digit numbers it converges to 495 in at most 6 steps. Other digit counts behave differently: 2-digit numbers fall into a 5-cycle, 5-digit numbers into longer cycles. The tool traces each step and detects whether the iteration reaches a fixed point or settles into a cycle. Everything runs locally in your browser.
Result
Step trace
Kaprekar's routine is a digit-manipulation iteration invented by the Indian schoolteacher D. R. Kaprekar. Fix a number of digits k; at each step write the current value padded to k digits (with leading zeros), sort the digits descending into K₁ and ascending into K₂, and replace the value with K₁ − K₂. For k=4 the routine is a mathematical curiosity: every starting value that is not a repdigit (all four digits equal) reaches the fixed point 6174 in at most 7 iterations — and 6174 maps to itself (7641 − 1467 = 6174), so it stays there. Repdigits collapse to 0. For k=3 the constant is 495 (≤6 steps). Not every digit count has a single fixed point: k=2 has no fixed point and instead falls into the 5-cycle 09 → 81 → 63 → 27 → 45 → 09, and k=5 has several longer cycles. The tool keeps k fixed (padding with leading zeros) so the digit count is preserved through the iteration, and it detects convergence by spotting the first repeated value — a period of 1 is a fixed point, a longer period a cycle. Pairs with the Number Properties, Collatz Conjecture, and Happy Numbers tools. Everything runs locally — nothing leaves your browser.