Kaprekar's constant

Take four digits that aren't all the same. Arrange them largest first, then smallest first, and subtract. Do it again with the answer. Within seven rounds you reach 6174, and 6174 only ever gives back 6174.

Run a number

Fewer than four digits get zeros in front, so 21 runs as 0021.

7641 − 1467 = 6174, right back where it started. Type four digits that aren't all the same to send them here.

All 10,000 at once

Each square is one number, 0000 at the top left to 9999 at the bottom right, shaded by how many rounds it takes. Point at one to see its route; tap it to run it.

Every number takes its rounds at the same time.

Rounds to reach 6174

    The ten repdigits, like 1111 and 7777, fall to 0000 and stay there.

    Why it gets there so fast

    Write the digits largest first as a ≥ b ≥ c ≥ d. One round is

      (1000a + 100b + 10c + d)− (1000d + 100c + 10b + a)= 999(a − d) + 90(b − c)

    Only the two gaps, a − d and b − c, survive the subtraction, and there are just 55 ways to pick them. So the first round squeezes all 10,000 numbers onto 55 values. That's the first jump when you run all 10,000. Six more rounds drain them all into 6174, except 0000, where the ten repdigits stay.

    D. R. Kaprekar described the routine in 1949. Three digits do the same thing and stop at 495. With two digits, or five or more, no single number catches them all; they end in loops instead, or split between several.