Playground · 6174
Kaprekar’s routine.
Every four-digit number ends up at 6174. I didn’t believe it either.
I found a video about 6174 and couldn’t leave it alone. The claim sounded too easy, take almost any four-digit number, follow one simple rule, and you always land on the same answer. I went digging (looking for calculators, read articles, watched more videos) until I understood why, then built this so you can see it for yourself.
The rule
Take a four-digit number with at least two different digits. Sort its digits from high to low, then from low to high, and subtract the smaller arrangement from the larger. Do it again with the answer. Keep going and you will always reach 6174, Kaprekar’s constant, in seven steps or fewer. Once you’re there, the routine sticks forever.
The maths
Leading zeros count, so 3087 sorts to 8730 and 0378. Numbers whose digits are all the same, like 1111, are the one exception: they collapse to 0000 instead.
Any four digits, as long as they are not all the same.