most seven iterations. A similar constant for 3 digits is 495. However, in base 10 a single such constant only exists for numbers of 3 or 4 digits; for other digit lengths or bases other than 10, the Kaprekar's routine algorithm described above may in general terminate in multiple different constants or repeated cycles, depending on the starting value. Python Code to test kaprekar's constant: KAPREKAR_CONSTANT = 6174 n = 1234 print(f'n = {n}') while True: digits = [] for i in range(4): digits.append(n % 10) n //= 10 digits.sort(reverse=True) large = 0 for d in digits: large = large * 10 + d digits.sort() small = 0 for d in digits: small = small * 10 + d n = large - small print(f'{large:>4} - {small:>4} = {n:>4}') if n == KAPREKAR_CONSTANT: break Kaprekar number Another class of numbers Kaprekar described are Kaprekar numbers. A Kaprekar number is a positive integer with the property that if it is squared, then its representation can be partitioned into two positive integer parts whose sum is equal to the original number (e.g. 45, since 452=2025, and 20+25=45, also 9, 55, 99 etc.) However, note the restriction that the two numbers are positive; for example, 100 is not a Kaprekar number even though 1002=10000, and 100+00 = 100. This operation, of taking the rightmost digits of a square, and adding it to the integer formed by the leftmost digits, is known as the Kaprekar operation. Some examples of Kaprekar numbers in base 10, besides the numbers 9, 99, 999, …, are : Devlali or self number In 1963, Kaprekar defined the property which has come to be known as self numbers, as the integers that cannot be generated by taking some other number and adding its own digits to it. For example, 21 is not a self number, since it can be generated from 15: 15 + 1 + 5 = 21. But 20 is a self number, since it cannot be generated from any other integer. He also gave a test for verifying this property in any number. These are sometimes referred to as Devlali numbers (after the town where he lived); though this appears to have been his preferred designation, the term "self number" is more widespread. Sometimes these are also designated Colombian numbers after a later designation. Harshad number Kaprekar also described the harshad numbers which he named harshad, meaning