# Theo Todman's Web Page - Notes Pages

## Blog

### Kaprekar's Constant

(Text as at 04/06/2020 23:48:29)

• A friend alerted me to an interesting mathematical phenomenon, described here: Guardian: 6174 (Kaprekar's Constant), though there are discussions on Wikipedia: Kaprekar's routine.
• Basically, it’s a fascinating fact that if you take any 4-digit number, sort its digits ascending and descending to give two further 4-digit numbers, take the smaller from the larger, and repeat the process until the number repeats in consecutive calculations, then you always end up with the number 6174 in 7 or fewer iterations. 6,174 is Kaprekar’s number, after the Indian mathematician who discovered the process (Wikipedia: 6174 - Kaprekar's Number).
• You have to avoid degenerate numbers like “1111”, which transform onto 0 immediately.
• I wrote a program in Access VBA (Kaprekar_Main) to check this out, and find out how many iterations each 4-digit number took, and store the results in a database. I made the process generic so that it could run for numbers of different lengths, but put a throttle on the number of iterations (a parameter set to 20) as for 5-digit and longer numbers, there are in general no universal solutions, though there are usually “Fixed points of the Kaprekar mapping” that map onto themselves, but in general most numbers cycle round without encountering one of these.
• When I ran it for 3-digit numbers they all (other than the degenerates) converged to 495.
• Running for 5-digit and 7-digit numbers produced no fixed points.
• Running for 6-digit numbers produced two fixed points (631764 and 549945).
• Finally, running for 8-digit numbers also produced two fixed points (63317664 and 97508421). The run took 5 hours as I was trying to determine the number of numbers that converged within a 20-iteration limit. To find the fixed points I’d only need one iteration, but as the process is escalating exponentially, I wouldn’t get much further, so there seemed no point.
• In any case, the spade-work has been done elsewhere, as is revealed by a page on OEIS: The On-Line Encyclopedia of Integer Sequences, namely OEIS: Fixed Points of the Kaprekar Mapping, which contains a link to a simple list: OEIS: Table of Kaprekar Numbers, which confirms that I’d got the fixed points up to 8 digits all present and correct.
• For the record, the table of number-length, fixed points, and count of numbers converging within n iterations, is given below. It was interesting that all the 6 and 8-digit numbers that converged did so in 4 or fewer iterations.
• I’ve not yet followed up the various OEIS links, and probably won’t.

LengthFinal Number1234567Total
309      9
349515014427022215054 990
409      9
461743845762,4001,2721,5181,6562,1849,990
509      9
609      9
65499451,950      1,950
66317648,16012,36039,1202,880   62,520
709      9
809      9
86331766469,440198,240308,33623,520   599,536
897508421604,8001,505,280260,960    2,371,040

Note last updated Reference for this Topic Parent Topic
04/06/2020 23:48:29 1304 (Kaprekar's Constant) None

To access information, click on one of the links in the table above.

### Text Colour Conventions

1. Blue: Text by me; © Theo Todman, 2020