Seven Steps to 6174
Take any four-digit number that is not a repdigit. Sort its digits big-to-small, sort them small-to-big, subtract. Repeat. In at most seven steps you land at 6174, and 6174 sends itself back. Every one of the 8,991 non-repdigit four-digit numbers is enumerated live, in your browser, below.
D. R. Kaprekar noticed this in 1949, in Devlali, India. The rule fits on a napkin. The proof that it always halts is finite in the strong sense: there are only ten thousand four-digit numbers, so you can just check them all. Which is what this page does, in the milliseconds after you load it.
The full census
The routine has ten thousand possible starting values in the four-digit domain (0000 to 9999, leading zeros allowed). Ten of them are repdigits and go to zero in one step. The other 9,990 all reach 6174, and none of them takes more than 7 steps to get there. Here is the distribution of how many take exactly zero, one, two, up to seven steps, over the classical range 1000 to 9999 (the version most sources report):
The three-digit cousin
The same rule with three digits collapses every non-repdigit start to 495, in at most six steps. Pick 3-digit above and try any 3-digit number: for instance, 100 goes 100 (as digits {0,0,1}) to 099 to 891 to 792 to 693 to 594 to 495, which is exactly six steps and the slowest possible.
The base-10 catalog
Which digit-lengths, in base ten, share this "everything falls to one number" property with the four-digit case? We enumerated every start for digit-counts two through eight (over a hundred million evaluations in total). Only two digit-lengths yield a single nonzero fixed point that catches every non-repdigit. Here is what the map looks like:
Basins count non-repdigit starts over 0 to 10k - 1 (leading zeros allowed). Rows k = 3 and k = 4 are the two Kaprekar constants; everywhere else in this range the map ends in cycles or splits its attention.
The check
Live in your browser, at page load: the four-digit domain 0 to 9999 was enumerated, every non-repdigit routed by the routine, and the trap-time recorded. The count of non-repdigits was –, the number of distinct attractors was –, the attractor was –, and the maximum trap-time was –. The three-digit domain gave attractor – with maximum trap-time –.
The catalog rows for k = 5, 6, 7, 8 were computed once, out-of-browser, in research/kaprekar/census.mjs, and are quoted verbatim above; the same script runs a self-check on k = 2, 3, 4 and matches this page bit-for-bit. What is machine-verified: the exhaustive enumeration for k = 2 through 8. What is not proved here: that k = 9 and larger have no unique Kaprekar constant either. Nothing is asserted here that this page does not recompute or that the census file does not carry.