Skip to main content


Showing posts from April, 2022

Coding Kaprekar Constants

Here is an interesting play with numbers. Take any three-digit number, for example 276, subtract its digits i.e. 276 in descending order by the digits in ascending order, e.g., 762–267 and keep repeating this process; eventually, it will reach a constant, namely 495. Try this same method for a four-digit number and it will reach the number 6174. Try the same method for six digits, and we will arrive at two constants, i.e. 54994 and 631764, and one loop. Interestingly this phenomenon was noted by an Indian Mathematician  Dr Kaprekar  in the year 1955, and these constants are called as  Kaprekar constants . To know more about Kaprekar Constant you can watch this video I challenged myself to code Kaprekar constant for all digits. I have made a code in python which finds all the 3,4, and 6 digit numbers that don’t follow the Kaprekar constant. Run the Code in Replit: Link to Medium Article