Kaprekar’s Constant on 4‑digit States

An exhaustive, client‑side sweep of every 4‑digit state (keeping leading zeros) that runs Kaprekar’s routine, summarizes the results, and verifies them with reproducible checks.

1/ Answer Concise results

Universe size
Converge to 6174
(%)
Don’t converge (rep‑digits)
(%)
Max iterations to reach 6174
Average iterations (convergers)

2/ Reason why Mathematical explanation

Definition. Let K act on 4‑digit strings (leading zeros kept) as follows: write the digits in descending and ascending order to form two 4‑digit numbers, then subtract and pad with leading zeros to 4 digits. We denote the result by K(x).

Fixed points and traps. (i) 6174 is a fixed point: K(6174) = 6174. (ii) For every rep‑digit aaaa, the ascending and descending sorts coincide, so K(aaaa) = 0000 and then K(0000) = 0000. Thus the only non‑converging starts are the ten rep‑digits, which fall into the absorbing state 0000.

Claim. Every non‑rep‑digit 4‑digit state reaches 6174 in finitely many steps. The map K acts on the finite set of 10,000 states. Aside from the trap at 0000 (reached exactly by rep‑digits), there are no other cycles; consequently every orbit that avoids 0000 must flow into the fixed point 6174. Our harness below confirms this by exhaustive enumeration and shows that the worst‑case time‑to‑reach is 7 steps.

In short: rep‑digits collapse to 0000; everything else flows to the unique fixed point 6174.

3/ Checks (harness) Exhaustive sweep 0000–9999

Check 1 — Universe accounting

Do convergers + non‑convergers add up to 10,000?

Convergers: Non‑convergers: Sum:
Check 2 — Only rep‑digits fail to converge
Check 3 — Max iterations equals 7
max = avg =
Check 4 — Distribution sums to converger count; includes k=0
Iteration distribution
k stepscountpercentexample path
Check 5 — Fixed point & zero‑padding invariant
  • step(6174) =
  • All intermediate states are 4‑digit strings:

Appendix How this page checks things

Everything is computed on page load by sweeping all 10,000 states with leading zeros kept. You can view source to see the tiny harness.