ExplorationsKaprekar’s routine on four decimal digits

The 6174 Attractor

Exhaustively checkedDigitsIterationFixed pointscurious

Write a whole number from 0 to 9999 using four digits, adding leading zeroes if needed. Arrange its digits from largest to smallest and from smallest to largest, then subtract the smaller arrangement from the larger and repeat. For instance, 3524 gives 5432 − 2345 = 3087. Unless all four digits are identical, this reaches 6174 within seven steps, and the same rule leaves 6174 unchanged.

Current view: Digit machine

Watch the same digits copy, travel into both arrangements, and subtract from right to left.

Digit machine · base 10 · 4 digits3524
Starting from
3
5
2
4

Press Step to watch these digits copy, rearrange, and subtract.

Whole-space preview

See where this route sits among every starting group

Building the complete state-space preview with exact arithmetic.
tile
one digit of the number being worked
largest / smallest
blue moves biggest-first; grey moves smallest-first - the digits stay the same
difference
what the subtraction gives, and the next starting value

Each tile is one digit. The heavy row is where this step started; blue travels into largest-first order, grey into smallest-first order, and vermilion resolves from right to left as the difference. That difference becomes the next starting value.

Ready at 3524. Run or step to sort the digits, subtract, and see where it lands.

Now
3524
Steps taken
0 / 3
Status
Running

Starting value

Use any value from 0000 to 9999. It does not need to be greater than 1000, and leading zeroes count.

Step by step

Use Step for one change you can inspect, or Run to watch the changes accumulate.

Speed
Advanced parameters
Digit count

Three digits converge on 495 instead. The constant is a property of the base and width, not of the rule.

Cases worth seeing

Try this

Find a starting value that takes the full seven steps.

1/5

What is going on

Each explanation begins with a worked example and follows the same operation through intuition, formal statements and proofs. Later sections distinguish what is established from questions that remain open, so you can follow the level of detail useful to you.

Worked by handThe routine run by hand from 2718, until it stops going anywhere.
  1. 27188721 − 12787443largest arrangement minus smallest
  2. 74437443 − 34473996already the largest arrangement
  3. 39969963 − 36996264
  4. 62646642 − 24664176the same digits as 6174 - but not 6174
  5. 41767641 − 14676174one more step, and now it is
  6. 61747641 − 14676174and now it cannot leave

Now do that for all ten thousand four-digit starts at once and place each one by how many steps it still needs. That is the view: 6174 at the centre, and a ring for every step. 2718 above would sit five rings out.

Five steps to 6174, and then it is stuck - 6174 sorts to 7641 and 1467, and the difference is 6174 again. Watch step four especially: 4176 has exactly the same digits as 6174 and is not 6174, and it still needs one more step. That is not special to 2718. Every four-digit start except the ones with four identical digits ends in the same place, and none takes more than seven steps.

01

What you are seeing

A plain description of the process

Use four digits, allowing leading zeroes such as 0352. Sort all four digits into the largest arrangement and the smallest arrangement, then subtract the smaller from the larger. Write the result in four places, adding leading zeroes if needed, before sorting again.

For 3524, the first subtraction is 5432 − 2345 = 3087. The next is 8730 − 0378 = 8352, followed by 8532 − 2358 = 6174. At 6174 the same operation gives 7641 − 1467 = 6174, so repeating it no longer changes the value.

Every four-place start with at least two different digits reaches 6174 within seven steps. Four identical digits form the exception: 1111 − 1111 = 0000, and 0000 stays at zero. The leading-zero convention is part of the rule, not a requirement that the starting value be greater than 1000.

02

Why it starts to make sense

Intuition, before any algebra

Two things are quietly happening.

The rule cannot see the order you typed. Its first act is to sort. So 3524, 2345 and 5432 all take the same first step, and from there their runs are identical. Ten thousand starting values behave like only 715 different ones, which is already a far smaller problem than it looked.

The rule cannot produce most numbers. Subtracting two arrangements of the same digits turns out to be very constraining: only certain values can ever appear. So after a single step, the routine is already confined to a small, structured set - and once you are inside a small set and every element has somewhere to go, you cannot wander forever. You must eventually repeat yourself.

Switch to the view and both facts become visible at once. Everything drains inward, no branch is longer than seven rings, and the ten values that never arrive sit off to one side.

03

The key idea

The that does the work

Here is the constraint. Write the sorted digits as . The largest arrangement is and the smallest is . Subtract:

Both are multiples of nine. Every value after the first step is divisible by nine - which immediately rules out eight of every nine numbers.

The same argument works in any base . The two arrangements are of one another, so they have the same , so they are , so their difference is divisible by . Nothing about is special here.

04

Formal statement

Precisely what is being claimed

Let be the map sending a four-digit string to the difference between the descending and ascending arrangements of its digits, with the result written back as four digits (retaining leading zeroes).

Then for every four-digit string whose digits are not all equal:

and . For the ten strings with all digits equal, and .

Note what the statement is careful about: it is about four-digit strings, not about below ten thousand. Those are different objects, and the difference matters - 0999 is a legitimate state of this system and 999 is not.

05

Proof

Complete, and it runs on this page

The is exhaustion, and unusually, that is not a compromise.

There are exactly 10,000 four-digit strings. Each has exactly one successor. So the whole system is a finite in which every has out-degree one - and such a graph is always a set of with trees feeding into them, with no third possibility.

Enumerating all 10,000 settles it completely: there are exactly two , both of length one

  • 6174 and 0000 - and every valid start reaches 6174 within seven steps. The view is not an illustration of this argument. It is the argument, drawn.

One trap worth naming, because it is easy to fall into and this page fell into it first. Since the routine sorts its input, it is tempting to treat the digit multiset as the state and work with 715 instead of 10,000. That is right about transitions and wrong about states. 6174 and 4176 have the same digits, but 6174 is the while 4176 still needs one more step - and 4176 really does occur: any start whose sorted digits satisfy and produces it, such as 9755. Collapsing the two together understates the distance of every path that lands on a rearrangement of 6174 rather than on 6174 itself. The distances here are measured on numbers for that reason.

This is worth dwelling on, because it is the exception rather than the rule. The computation here is a only because the space is finite and every case was checked. The same computation over an infinite space would prove nothing whatsoever, however many cases it got through - which is exactly the situation for the Collatz map, whose statement looks almost identical to this one and remains open after eighty years.

06

Limits and frontier

Where this page stops being able to help

Three honest boundaries.

The constant is not a property of the rule. It is a property of the rule together with and four digits. Three digits give 495. Most other of base and width give of length greater than one, or several , or both. Nothing above explains why four decimal digits should be so unusually tidy - it is checked, not understood.

Divisibility by nine is not the whole explanation. It shows the space collapses. It does not single out 6174, and no short argument here does. If you want the destination rather than the , the enumeration is currently the honest answer.

Nor is "sorting means the multiset is the state". As above, that shortcut is false in exactly one place - at the - and the failure is invisible unless you check. It is a fair miniature of why this site distinguishes what has been checked from what merely sounds right.

The general base question is harder than it looks. Describing the structure for arbitrary base and digit count is a real research question rather than an exercise, and this page does not attempt it. See the sources below for the base-dependent treatment.

What is actually established

Every statement on this page, with its status, its exact scope, and the date that status was last checked.

Proved

Every four-digit base-10 starting value with at least two distinct digits reaches 6174 within seven iterations of the routine.

Scope
All 9,990 four-digit decimal strings 0000–9999 whose digits are not all identical, under the standard rule with leading zeroes retained.
Why
The four-digit decimal state space is finite - 10,000 strings - and every one of them has exactly one successor. Checking them all is therefore a complete proof rather than mere evidence, which is what makes this exploration unusual: the computation on this page is the argument.
Computation (exact)
This page enumerates all 10,000 four-digit strings in your browser using exact integer arithmetic on digit arrays, with no floating point and no sampling. Distances are measured on the strings themselves, not on digit multisets, because 6174 and its other digit arrangements are different states. Algorithm kaprekar-kernel-2.
Status checked
Proved

6174 is a fixed point of the routine: 7641 − 1467 = 6174.

Scope
Four-digit base-10 arithmetic.
Why
A single subtraction settles it, and you can check it by hand.
Status checked
Proved

After one iteration in base b, every value is divisible by b − 1; in base 10, by 9.

Scope
All bases and digit counts, for any start.
Why
The two arrangements are permutations of the same digits, so they have equal digit sums and are congruent modulo b − 1. Their difference is therefore divisible by b − 1.
Status checked
Proved

The ten repdigit starts (0000, 1111, …, 9999) reach 0000 in one step and never reach 6174.

Scope
The ten four-digit decimal strings whose digits are all equal.
Why
Sorting a repdigit gives the same arrangement both ways, so the subtraction is zero, and zero maps to itself.
Status checked
Exhaustively checked

Seven iterations are necessary as well as sufficient: some starting values need all seven.

Scope
All 9,990 valid four-digit decimal starts.
Why
The longest runs in the complete enumeration take exactly seven steps, so the bound cannot be lowered.
Computation (exact)
Established by complete enumeration of all 10,000 four-digit strings in your browser using exact integer arithmetic. Exactly 2,184 of the 9,990 valid starts require the full seven steps. Complete for four decimal digits, and no evidence at all about other widths or bases. Algorithm kaprekar-kernel-2.
Status checked
Proved

The same routine on three decimal digits reaches the constant 495 instead.

Scope
All three-digit decimal strings 000–999 whose digits are not all identical.
Why
The three-digit space is likewise finite and is enumerated completely by this page.
Computation (exact)
Complete enumeration of all 1,000 three-digit strings using the same exact kernel; 990 of them arrive, none needing more than six steps. Algorithm kaprekar-kernel-2.
Status checked
Proved

The routine’s next value depends only on the digit multiset, but the multiset is not the state: 6174 and its 23 other digit arrangements share a multiset while sitting at different distances from the attractor.

Scope
Four-digit base-10 strings; the same distinction applies to any base and width with a non-trivial fixed point.
Why
A rearrangement such as 4176 is genuinely reachable - any start whose sorted digits satisfy a − d = 4 and b − c = 2 produces it, for instance 9755 - and it needs one further step to become 6174. Treating multisets as states therefore understates distances, so this page measures them on the strings themselves.
Status checked
Proved

A single attracting constant is a feature of this base and width, not of the routine. Most base-and-width combinations produce cycles instead, or several attractors.

Scope
General statement about Kaprekar’s routine across bases; the behaviour of any particular base and width is decidable by finite enumeration.
Why
Each base-and-width pair gives its own finite state space with its own attractor structure. The tidiness of four decimal digits is a coincidence of this case rather than a general law.
Status checked

Sources

Review notes show which bibliographic details Mathomaly has checked and which remain unresolved. Checking a publication record does not independently verify its proof.

  1. D. R. Kaprekar, Another solitaire game, Scripta Mathematica 15, pp. 244–245, 1949. Link

    An early published account of Kaprekar's routine. The journal bibliography supplies the volume and pages; the original printed article was not inspected.

    Bibliographic record checked. This is not an independent verification of the proof.

    Bibliographic review:

    AI-assisted bibliographic audit. Evidence type: library record.

    Checked the Kaprekar:1949:ASG entry in the University of Utah's journal bibliography.

  2. A099009 - Fixed points of the Kaprekar mapping, The On-Line Encyclopedia of Integer Sequences. Link

    Lists Kaprekar fixed points including 6174. The laboratory separately enumerates the fixed-width four-position routine.

    Bibliographic record checked. This is not an independent verification of the proof.

    Bibliographic review:

    AI-assisted bibliographic audit. Evidence type: source text.

    Checked the sequence identifier, definition and displayed initial terms on the database entry.

  3. A151949 - The Kaprekar map, The On-Line Encyclopedia of Integer Sequences. Link

    Defines descending digits minus ascending digits without a fixed four-position width. For example, its value at 15 is 36; the laboratory pads to 0015 and obtains 5085. These are different conventions.

    Bibliographic record checked. This is not an independent verification of the proof.

    Bibliographic review:

    AI-assisted bibliographic audit. Evidence type: source text.

    Checked the sequence identifier, definition and displayed initial terms on the database entry.

  4. Daniel Hanover, The Base Dependent Behavior of Kaprekar's Routine: A Theoretical and Computational Study Revealing New Regularities, arXiv:1710.06308, 2017. Link

    Studies three-digit Kaprekar constants in different bases and reports computational patterns in their iteration counts.

    Bibliographic record checked. This is not an independent verification of the proof.

    Bibliographic review:

    AI-assisted bibliographic audit. Evidence type: author record.

    Author submission confirms full title, author and October 2017 date; scope is chiefly the three-digit case.

Connected by how they work, not by sharing a topic label.