Skip to main content

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:

https://replit.com/@Saipranavsg/Kaprekar-Numbers?v=1#main.py

Link to Medium Article https://medium.com/@saipranavsg/kaprekar-constants-bcb35a088788

Comments

Popular posts from this blog

Certificate of Excellence from MIT app Inventor

I was elated to recieve the certificate from the App Inventor Foundation which states i have RECEIVED Honorable Mention IN THE Youth Team CATEGORY FOR THEIR APP AllergyAlly AS PART OF THE GLOBAL AI HACKATHON 2024.  I have earlier received recognition for my app VOX in 2021 from MIT app Inventor as well 

AllergyAlly a mobile app

  AI-powered allergy companion app that revolutionizes allergy management. The mobile app was developed as part of submission to the  Global AI Hackathon  using the  MIT app inventor platform  by me and my teammate Viraj Marathe. UPDATE: The Allergy Ally app secured the Honourable Mention Award at the Global AI Hackathon. The World Allergy Organization estimates that 20–30% of the global population experiences some form of allergy. Impact on Quality of Life by Allergies: Missed days Poor Sleep Dietary Restrictions Mental Health Medical history remains a cornerstone in allergy diagnosis, guiding healthcare providers in making informed decisions and providing appropriate care to patients. And this app documents each and every allergic incident and provides detailed report for the healthcare providers with the help of AI. Existing solutions are not satisfactory and our mobile app Allergy ally acts as a companion to persons troubled by allergies. Features of the ap...

Dataset generation for mobile app testing

As part of MIT app inventor Hackathon, i and my teammate Viraj Marathe have developed a mobile app AllergyAlly. This AI-powered allergy companion app aims to revolutionise allergy management. Medical history remains a cornerstone in allergy diagnosis, guiding healthcare providers in making informed decisions and providing appropriate care to patients. And this app documents each and every allergic incident and provides detailed report for the healthcare providers with the help of AI. Existing solutions are not satisfactory and our mobile app Allergy ally acts as a companion to persons troubled by allergies. For the rigorous testing of the mobile app we needed a dataset that we could use in the app so that the features of the app could be tested for accuracy. We created a dataset Used python to generate patient allergy incident logs for every 2 days of a year The dataset has the symptoms, triggers, weather summary, mood levels and severity with a pattern to it and is not completely rand...