aiSee: Visualizing Kaprekar’s Operation

Kaprekar's operation

Kaprekar’s operation, named after the Indian mathematician D. R. Kaprekar, refers to:

  1. taking any number with at least two different digits (say, 312),
  2. reordering its digits from highest to lowest (→ 321)
    and from lowest to highest (→ 123),
  3. and then subtracting the second number from the first (321 − 123 = 198).

The above graphs document Kaprekar’s operation for 3-digit and 4-digit numbers, respectively. In the first graph, the operation is represented by edges, in the second by subgraphs.

Visualizing the graphs with aiSee reveals that repeating the operation for any given 3-digit number will always get you to 495, after which you'll enter an endless loop (954 − 459 = 495). Similarly, repeating the operation for any 4-digit number will always get you to 6174 and another endless loop (7641 − 1467 = 6174).

Further reading