## Friday, August 27, 2010

### Kaprekar's constant

Kaprekar's constant is arrived at by following these steps:
1. Take any four-digit number whose digits are not all the same (leading zeroes are allowed).
2. Sort the digits in descending then ascending order, making the largest and smallest possible 4-digit numbers composed of those digits. (Add leading zeroes if necessary.)
3. Subtract the smaller number from the larger number. The result will be another 4-digit number.
4. Repeat the process starting with the result.
For example, starting with the digits 0827 (today's date) we get:

8720 - 0278 = 8442
8442 - 2448 = 5994
9954 - 4599 = 5355
5553 - 3555 = 1998
9981 - 1899 = 8082
8820 - 0288 = 8532
8532 - 2358 = 6174

If we continue the process outlined above the result will always be 6174.

7641 - 1467 = 6174

The amazing thing is that starting with any 4-digit number whose digits are not all the same will result in 6174 in at most seven steps. 6174 is called the Kaprekar constant for 4-digit numbers after Dattaraya Ramchandra Kaprekar who discovered the property in 1949.

There's a Kaprekar constant for 3-digit numbers as well. Following the same procedure above starting with any 3-digit number whose digits are not all the same will end in the result of 495 in at most six steps. Applying the same process to base 10 numbers with any other number of digits will result in either zero or a cycle that never ends. (Check out the article Mysterious number 6174 by Yutaka Nishiyama for the proof.)

You can see the results of the Kaprekar routine for 3-digit or 4-digit numbers using the utility below. Just enter a number in the first field and click the "Calculate" button. The results will appear below.

Jarrod said...

Sounds like he was bored in school :)

Bill the Lizard said...

Jarrod,
It does look like the kind of thing you'd find in the margin of a particularly dull text book. :)

Your comment reminded me of the origin of the Ulam spiral.

"It was discovered by the mathematician Stanislaw Ulam in 1963, while he was doodling on scratch paper at a scientific meeting."

mwm said...

Amazing!

CalcDave said...

I'm curious, though, how would one go about "proving" this (other than making all the possible "cases" and checking them)?

Bill the Lizard said...

CalcDave,
Great question! I had thought that it would be reasonable to go through all the possible cases, since there are only 110 for 3-digit numbers and 200 for 4-digits, but I found that there's a much more elegant proof. Check out the article Mysterious number 6174 by Yutaka Nishiyama.

Bill the Lizard said...

CalcDave,
I added that link to the body of the post as well because I think it really adds a lot. Thanks a lot for a great question.

JuanPi said...

Hi, a simple one is created by the TOE and TOEZ rule (fixed point and periodic orbit!)
Explanations here
http://lavidasegunjuanpi.blogspot.com/2009/03/dynamical-entities.html

Jakub Vrána said...

Why do you think that there is 110 or 200 cases for 3 resp. 4 digits numbers? I think there are 210 resp. 705 cases.

Bill the Lizard said...

Jakub,
You're right. I took it to be C(10, 3) = 120 and C(10, 4) = 210, and subtracted 10 from each for the 10 rep-digit values. I forgot to allow for repetition when computing the combinations, so it should be 210 and 705. Thanks for pointing that out.