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.
Wikipedia
- Take any four-digit number, using at least two different digits (leading zeros are allowed).
- Arrange the digits in descending and then in ascending order to get two four-digit numbers, adding leading zeros if necessary.
- Subtract the smaller number from the bigger number.
- Go back to step 2 and repeat.
Following the above steps always leads you to the same number, Kaprekar’s Constant: 6174.
8541 - 1458 = 7083 |
8730 - 0378 = 8352 |
8532 - 2358 = 6174 |