Kaprekar’s Constant

This code demo was published on .

I came across an interesting mathematical observation today called Kaprekar’s constant, named after the mathematician, Dattatreya Ramchandra Kaprekar, and built an interactive tool to demonstrate it.

  1. Take any four-digit number, using at least two different digits (leading zeros are allowed).
  2. Arrange the digits in descending and then in ascending order to get two four-digit numbers, adding leading zeros if necessary.
  3. Subtract the smaller number from the bigger number.
  4. Go back to step 2 and repeat.
Wikipedia

Following the above steps always leads you to the same number, Kaprekar’s Constant: 6174.

Kaprekar’s Constant Permalink

8541 - 1458 = 7083
8730 - 0378 = 8352
8532 - 2358 = 6174

You can also send an anonymous reply (using Quill and Comment Parade).