Kaprekar constant, or 6174, is a constant that arises when we take a 4-digit integer, form the largest and smallest numbers from its digits, and then subtract these two numbers. Continuing with this process of forming and subtracting, we will always arrive at the number 6174.
An illustration:
Take a 4-digit number like 3215. Rearranging to form the largest and smallest with these digits, we get 5321 and1235. Now, subtract them: 5321-1235 = 4086. Continue with the process of rearranging and subtracting:
8640−0468 =8172
8721−1278 =7443
7443−3447 =3996
9963−3699 =6264
6642−2466 =4176
7641−1467 =6174.
We stop here since we will only get into a loop and keep getting 6174